Hướng dẫn php color code list

Colors are displayed combining RED, GREEN, and BLUE light.


Color Names

With CSS, colors can be set by using color names:


CSS Color Values

With CSS, colors can be specified in different ways:

  • By color names
  • As RGB values
  • As hexadecimal values
  • As HSL values (CSS3)
  • As HWB values (CSS4)
  • With the currentcolor keyword

RGB Colors

RGB color values are supported in all browsers.

An RGB color value is specified with: rgb( RED , GREEN , BLUE ).

Each parameter defines the intensity of the color as an integer between 0 and 255.

For example, rgb(0,0,255) is rendered as blue, because the blue parameter is set to its highest value (255) and the others are set to 0.

Example

ColorRGBColor
  rgb(255,0,0) Red
  rgb(0,255,0) Green
  rgb(0,0,255) Blue

Try it Yourself »

Shades of gray are often defined using equal values for all the 3 light sources:

Example

ColorRGBColor
  rgb(0,0,0) Black
  rgb(128,128,128) Gray
  rgb(255,255,255) White

Try it Yourself »



Hexadecimal Colors

Hexadecimal color values are also supported in all browsers.

A hexadecimal color is specified with: #RRGGBB.

RR (red), GG (green) and BB (blue) are hexadecimal integers between 00 and FF specifying the intensity of the color.

For example, #0000FF is displayed as blue, because the blue component is set to its highest value (FF) and the others are set to 00.

Example

ColorHEXRGBColor
  #FF0000 rgb(255,0,0) Red
  #00FF00 rgb(0,255,0) Green
  #0000FF rgb(0,0,255) Blue

Try it Yourself »

Shades of gray are often defined using equal values for all the 3 light sources:

Example

ColorHEXRGBColor
  #000000 rgb(0,0,0) Black
  #808080 rgb(128,128,128) Gray
  #FFFFFF rgb(255,255,255) White

Try it Yourself »


Upper Case or Lower Case?

You can use upper case or lower case letters to specify hexadecimal values.

Lower case are easier to write. Upper case are easier to read.


Color Names

CSS supports 140 standard color names.

In the next chapter you will find a complete alphabetical list of color names with hexadecimal values:

Color NameHexColor
AliceBlue #F0F8FF  
AntiqueWhite #FAEBD7  
Aqua #00FFFF  
Aquamarine #7FFFD4  
Azure #F0FFFF  
Beige #F5F5DC  
Bisque #FFE4C4  


The currentcolor Keyword

The currentcolor keyword refers to the value of the color property of an element.

Example

The border color of the following

element will be blue, because the text color of the
element is blue:

#myDIV {
  color: blue; /* Blue text color */
  border: 10px solid currentcolor; /* Blue border color */
}

Try it Yourself »



W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2022 by Refsnes Data. All Rights Reserved.
W3Schools is Powered by W3.CSS.

Bài này sẽ giới thiệu cú pháp (syntax) và các thành phần cơ bản trong PHP. Để học tốt bài này, các bạn cần đọc lại bài Cài đặt môi trường lập trình Web PHP với XAMPP để biết cách chạy ứng dụng web PHP với XAMPP.

Các file PHP chứa code PHP có đuôi mở rộng là .php. Một file PHP có thể bao gồm các thẻ (tag) HTML và PHP code. Các đoạn code PHP (còn gọi là PHP script) có thể được đặt ở bất cứ đâu trong file PHP.

PHP script bắt đầu với và kết thúc với ?>:


Trong thư mục C:\xampp\htdocs\gochocit, tạo file index.php với nội dung như bên dưới.



Góc Học IT - Học công nghệ thông tin online

Hello everyone,

Trong ví dụ trên, file index.php chứa các thẻ HTML và PHP script. Sử dụng trình duyệt web và truy cập địa chỉ http://localhost/gochocit/ để được kết quả thực thi của file trên.

Trong PHP, keyword (if, else, while, echo,…), class, function và user-defined function không phân biệt chữ hoa chữ thường. Nhưng tất cả tên biến (variable) thì có phân biệt chữ hoa chữ thường. Xem ví dụ bên dưới.

";
    echo "Welcome to gochocit.com!
"; EcHo "Welcome to gochocit.com!
"; $color = "red"; echo "My favorite color is " . $color . "
"; echo "My favorite color is " . $COLOR . "
"; echo "My favorite color is " . $coLOR . "
"; ?>
Kết quả
Welcome to gochocit.com!
Welcome to gochocit.com!
Welcome to gochocit.com!
My favorite color is red

Warning: Undefined variable $COLOR in C:\xampp\htdocs\gochocit\index.php on line 7
My favorite color is

Warning: Undefined variable $coLOR in C:\xampp\htdocs\gochocit\index.php on line 8
My favorite color is

Các câu lệnh ECHO, echo, EcHo là như nhau. Nhưng các biến $color, $COLOR$coLOR là khác nhau.

Chú thích (comment) sẽ không được thông dịch bởi PHP interpreter. Comment giúp diễn giải ý nghĩa của code, giúp người đọc code dễ hiểu hơn.

PHP hỗ trợ 3 cách viết comment:

– Comment trên một dòng với //

– Comment trên một dòng với #

– Comment trên nhiều dòng với /* */


3. Từ khóa (keyword) trong PHP

Từ khóa (keyword) là những từ (word) được dành riêng trong PHP. Chúng ta không thể sử dụng từ khóa để đặt tên biến, tên hàm hoặc bất kỳ định danh (identifier) nào khác. Chúng được sử dụng để xác định cú pháp và cấu trúc của ngôn ngữ PHP. Trong PHP, các từ khóa không có sự phân biệt chữ hoa và chữ thường.

__halt_compiler() abstract and array() as
break callable case catch class
clone const continue declare default
die() do echo else elseif
empty() enddeclare endfor endforeach endif
endswitch endwhile eval() exit() extends
final finally fn (PHP 7.4) for foreach
function global goto if implements
include include_once instanceof insteadof interface
isset() list() match (PHP 8.0) namespace new
or print private protected public
readonly (PHP 8.1.0) require require_once return static
switch throw trait try unset()
use var while xor yield

Ngoài ra, chúng ta còn có một số hằng số được định nghĩa trước (predefined constants).

__CLASS__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__
__NAMESPACE__ __TRAIT__        

4. Định danh (identifier) trong PHP

Các biến (variable), hằng (constant), hàm (function),… trong PHP đều phải có tên gọi riêng. Các tên gọi này gọi là định danh (identifier). Khi đặt tên định danh, chúng ta phải tuân thủ các quy tắc sau:

1. Tên định danh chỉ được phép chứa các chữ cái (A-Z, a-z), chữ số (0-9) và dấu gạch dưới _. Ví dụ, myClass, var_1print_this_to_screen là các tên định danh hợp lệ.

2. Ký tự đầu tiên trong tên định danh không được phép là chữ số. Ví dụ, tên định danh 1variable không hợp lệ nhưng variable1 thì hợp lệ.

3. Tên gọi không được trùng với từ khóa (keyword).

4. Không được sử dụng các ký hiệu đặc biệt như !, @, #, $,%,… trong tên định danh.

5. Tên định danh có thể có độ dài bất kỳ.

5. Câu lệnh (statement) trong PHP

Khi thực thi PHP script, từng câu lệnh (statement) sẽ được thực thi. Mỗi câu lệnh trong PHP phải được kết thúc bởi dấu chấm phẩy ;.

";
    $a = 5 +
    6 - 2
    + 4;
    echo $a;
?>
Kết quả
statement
13

Lưu ý: Một statement có thể được viết trên 1 hoặc nhiều dòng.

  • Chuyển đổi (convert) dữ liệu JSON sang dữ liệu XML trong Python
  • Tham số (parameter) của hàm trong Python
  • Cấu trúc rẽ nhánh if…else trong PHP
  • Lớp trừu tượng (abstract class) và interface trong PHP
  • Kỹ thuật lập trình với kiểu cấu trúc và con trỏ trong C++