Hướng dẫn what is a css color? - màu css là gì?

Kiểu dữ liệu

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

0 CSS đại diện cho một màu. Một
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

0 cũng có thể bao gồm giá trị độ trong suốt kênh alpha, cho biết làm thế nào màu nên tổng hợp với nền của nó.
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

0
CSS data type represents a color. A
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

0 may also include an alpha-channel transparency value, indicating how the color should composite with its background.

Một

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

0 có thể được xác định theo bất kỳ cách nào sau đây:

  • Sử dụng một từ khóa (chẳng hạn như
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    3 hoặc
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    4). Tất cả các từ khóa hiện có chỉ định một màu trong không gian màu SRGB.
  • Sử dụng hệ tọa độ khối RGB (thông qua các ký hiệu chức năng #-hexadecimal hoặc
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    5 và
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    6). Chúng luôn chỉ định một màu trong không gian màu SRGB.
  • Sử dụng hệ thống tọa độ hình trụ HSL (thông qua các ký hiệu chức năng
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    7 và
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    8). Chúng luôn chỉ định một màu trong không gian màu SRGB.
  • Sử dụng hệ thống tọa độ hình trụ HWB (thông qua ký hiệu chức năng
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    9). Chúng luôn chỉ định một màu trong không gian màu SRGB.
  • Sử dụng hệ tọa độ hình trụ LCH, thông qua ký hiệu chức năng
    <div>div>
    <hr />
    <label for="color">Enter a valid color value:label>
    <input type="text" id="color" />
    
    0. Điều này có thể chỉ định bất kỳ màu có thể nhìn thấy.
  • Sử dụng hệ tọa độ phòng thí nghiệm, thông qua ký hiệu chức năng
    <div>div>
    <hr />
    <label for="color">Enter a valid color value:label>
    <input type="text" id="color" />
    
    1. Điều này có thể chỉ định bất kỳ màu có thể nhìn thấy.
  • Sử dụng ký hiệu chức năng
    <div>div>
    <hr />
    <label for="color">Enter a valid color value:label>
    <input type="text" id="color" />
    
    2, để chỉ định màu trong nhiều không gian màu được xác định trước hoặc tùy chỉnh.

Cú pháp

Kiểu dữ liệu

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

0 được chỉ định bằng một trong các tùy chọn được liệt kê dưới đây.

Lưu ý: Mặc dù các giá trị ____1010 được xác định chính xác, nhưng ngoại hình thực tế của chúng có thể thay đổi (đôi khi đáng kể) từ thiết bị này sang thiết bị khác. Điều này là do hầu hết các thiết bị không được hiệu chỉnh và một số trình duyệt không hỗ trợ cấu hình màu của thiết bị đầu ra. Although

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

0 values are precisely defined, their actual appearance may vary (sometimes significantly) from device to device. This is because most devices are not calibrated, and some browsers do not support output devices' color profiles.

Màu sắc được đặt tên

Màu sắc được đặt tên là các định danh không nhạy cảm trường hợp đại diện cho một màu cụ thể, chẳng hạn như

<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />
5,
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

3,
<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />
7 hoặc
<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />
8. Mặc dù các tên ít nhiều mô tả màu sắc tương ứng của chúng, nhưng về cơ bản chúng là nhân tạo, không có lý do nghiêm ngặt đằng sau các tên được sử dụng.

Danh sách đầy đủ các từ khóa như vậy có sẵn ở đây.

Từ khóa hiện tại

Từ khóa

<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />
9 đại diện cho giá trị của thuộc tính ____30 của một phần tử. Điều này cho phép bạn sử dụng giá trị
div {
  width: 100%;
  height: 200px;
}
0 trên các thuộc tính không nhận được theo mặc định.

Nếu

<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />
9 được sử dụng làm giá trị của thuộc tính
div {
  width: 100%;
  height: 200px;
}
0, thì nó thay vào đó lấy giá trị của nó từ giá trị di truyền của thuộc tính
div {
  width: 100%;
  height: 200px;
}
0.

<div style="color: blue; border: 1px dashed currentcolor;">
  The color of this text is blue.
  <div style="background: currentcolor; height:9px;">div>
  This block is surrounded by a blue border.
div>

Mô hình màu RGB

Mô hình màu RGB xác định một màu nhất định trong không gian màu SRGB theo các thành phần màu đỏ, xanh lá cây và xanh dương của nó. Một thành phần alpha tùy chọn thể hiện độ trong suốt của màu.

Màu sắc RGB có thể được thể hiện thông qua cả thập lục phân (tiền tố với các ký hiệu

div {
  width: 100%;
  height: 200px;
}
5) và chức năng (
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

5,
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

6).

Ký hiệu thập lục phân:
div {
  width: 100%;
  height: 200px;
}
8 hoặc ____39

const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
0 (màu đỏ),
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
1 (màu xanh lá cây),
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
2 (màu xanh lam) và
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
3 (alpha) là các ký tự hexadecimal (0 Nott9, A, F).
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
3 là tùy chọn. Ví dụ,
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
5 tương đương với
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
6. Ký hiệu ba chữ số (
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
7) là phiên bản ngắn hơn của dạng sáu chữ số (
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
8). Ví dụ,
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
9 có cùng màu với
/* These syntax variations all specify the same color: a fully opaque hot pink. */

/* Hexadecimal syntax */
#f09
#F09
#ff0099
#FF0099

/* Functional syntax */
rgb(255,0,153)
rgb(255, 0, 153)
rgb(255, 0, 153.0)
rgb(100%,0%,60%)
rgb(100%, 0%, 60%)
rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */
rgb(255 0 153)

/* Hexadecimal syntax with alpha value */
#f09f
#F09F
#ff0099ff
#FF0099FF

/* Functional syntax with alpha value */
rgb(255, 0, 153, 1)
rgb(255, 0, 153, .5)
rgb(255, 0, 153, 0.5)
rgb(255, 0, 153, 100%)

/* Whitespace syntax */
rgb(255 0 153 / 1)
rgb(255 0 153 / 100%)

/* Functional syntax with floats value */
rgb(255, 0, 153.6, 1)
rgb(2.55e2, 0e0, 1.53e2, 1e2%)
0. Tương tự như vậy, ký hiệu RGB gồm bốn chữ số (
/* These syntax variations all specify the same color: a fully opaque hot pink. */

/* Hexadecimal syntax */
#f09
#F09
#ff0099
#FF0099

/* Functional syntax */
rgb(255,0,153)
rgb(255, 0, 153)
rgb(255, 0, 153.0)
rgb(100%,0%,60%)
rgb(100%, 0%, 60%)
rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */
rgb(255 0 153)

/* Hexadecimal syntax with alpha value */
#f09f
#F09F
#ff0099ff
#FF0099FF

/* Functional syntax with alpha value */
rgb(255, 0, 153, 1)
rgb(255, 0, 153, .5)
rgb(255, 0, 153, 0.5)
rgb(255, 0, 153, 100%)

/* Whitespace syntax */
rgb(255 0 153 / 1)
rgb(255 0 153 / 100%)

/* Functional syntax with floats value */
rgb(255, 0, 153.6, 1)
rgb(2.55e2, 0e0, 1.53e2, 1e2%)
1) là phiên bản ngắn hơn của dạng tám chữ số (
/* These syntax variations all specify the same color: a fully opaque hot pink. */

/* Hexadecimal syntax */
#f09
#F09
#ff0099
#FF0099

/* Functional syntax */
rgb(255,0,153)
rgb(255, 0, 153)
rgb(255, 0, 153.0)
rgb(100%,0%,60%)
rgb(100%, 0%, 60%)
rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */
rgb(255 0 153)

/* Hexadecimal syntax with alpha value */
#f09f
#F09F
#ff0099ff
#FF0099FF

/* Functional syntax with alpha value */
rgb(255, 0, 153, 1)
rgb(255, 0, 153, .5)
rgb(255, 0, 153, 0.5)
rgb(255, 0, 153, 100%)

/* Whitespace syntax */
rgb(255 0 153 / 1)
rgb(255 0 153 / 100%)

/* Functional syntax with floats value */
rgb(255, 0, 153.6, 1)
rgb(2.55e2, 0e0, 1.53e2, 1e2%)
2). Ví dụ,
/* These syntax variations all specify the same color: a fully opaque hot pink. */

/* Hexadecimal syntax */
#f09
#F09
#ff0099
#FF0099

/* Functional syntax */
rgb(255,0,153)
rgb(255, 0, 153)
rgb(255, 0, 153.0)
rgb(100%,0%,60%)
rgb(100%, 0%, 60%)
rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */
rgb(255 0 153)

/* Hexadecimal syntax with alpha value */
#f09f
#F09F
#ff0099ff
#FF0099FF

/* Functional syntax with alpha value */
rgb(255, 0, 153, 1)
rgb(255, 0, 153, .5)
rgb(255, 0, 153, 0.5)
rgb(255, 0, 153, 100%)

/* Whitespace syntax */
rgb(255 0 153 / 1)
rgb(255 0 153 / 100%)

/* Functional syntax with floats value */
rgb(255, 0, 153.6, 1)
rgb(2.55e2, 0e0, 1.53e2, 1e2%)
3 có cùng màu với
/* These syntax variations all specify the same color: a fully opaque hot pink. */

/* Hexadecimal syntax */
#f09
#F09
#ff0099
#FF0099

/* Functional syntax */
rgb(255,0,153)
rgb(255, 0, 153)
rgb(255, 0, 153.0)
rgb(100%,0%,60%)
rgb(100%, 0%, 60%)
rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */
rgb(255 0 153)

/* Hexadecimal syntax with alpha value */
#f09f
#F09F
#ff0099ff
#FF0099FF

/* Functional syntax with alpha value */
rgb(255, 0, 153, 1)
rgb(255, 0, 153, .5)
rgb(255, 0, 153, 0.5)
rgb(255, 0, 153, 100%)

/* Whitespace syntax */
rgb(255 0 153 / 1)
rgb(255 0 153 / 100%)

/* Functional syntax with floats value */
rgb(255, 0, 153.6, 1)
rgb(2.55e2, 0e0, 1.53e2, 1e2%)
4.

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

5 hoặc
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

6:
/* These syntax variations all specify the same color: a fully opaque hot pink. */

/* Hexadecimal syntax */
#f09
#F09
#ff0099
#FF0099

/* Functional syntax */
rgb(255,0,153)
rgb(255, 0, 153)
rgb(255, 0, 153.0)
rgb(100%,0%,60%)
rgb(100%, 0%, 60%)
rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */
rgb(255 0 153)

/* Hexadecimal syntax with alpha value */
#f09f
#F09F
#ff0099ff
#FF0099FF

/* Functional syntax with alpha value */
rgb(255, 0, 153, 1)
rgb(255, 0, 153, .5)
rgb(255, 0, 153, 0.5)
rgb(255, 0, 153, 100%)

/* Whitespace syntax */
rgb(255 0 153 / 1)
rgb(255 0 153 / 100%)

/* Functional syntax with floats value */
rgb(255, 0, 153.6, 1)
rgb(2.55e2, 0e0, 1.53e2, 1e2%)
7 hoặc
/* These syntax variations all specify the same color: a fully opaque hot pink. */

/* Hexadecimal syntax */
#f09
#F09
#ff0099
#FF0099

/* Functional syntax */
rgb(255,0,153)
rgb(255, 0, 153)
rgb(255, 0, 153.0)
rgb(100%,0%,60%)
rgb(100%, 0%, 60%)
rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */
rgb(255 0 153)

/* Hexadecimal syntax with alpha value */
#f09f
#F09F
#ff0099ff
#FF0099FF

/* Functional syntax with alpha value */
rgb(255, 0, 153, 1)
rgb(255, 0, 153, .5)
rgb(255, 0, 153, 0.5)
rgb(255, 0, 153, 100%)

/* Whitespace syntax */
rgb(255 0 153 / 1)
rgb(255 0 153 / 100%)

/* Functional syntax with floats value */
rgb(255, 0, 153.6, 1)
rgb(2.55e2, 0e0, 1.53e2, 1e2%)
8

const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
0 (màu đỏ),
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
1 (màu xanh lá cây) và
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
2 (màu xanh lam) có thể là
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
2S hoặc
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
3S, trong đó số
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
4 tương ứng với
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5.
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
3 (alpha) có thể là
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
2 giữa
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
8 và
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
9 hoặc
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
3, trong đó số
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
9 tương ứng với
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 (độ mờ hoàn toàn).

Mô hình màu HSL

Mô hình màu HSL xác định một màu nhất định trong không gian màu SRGB theo màu sắc, độ bão hòa và các thành phần độ sáng của nó. Một thành phần alpha tùy chọn thể hiện độ trong suốt của màu.

Nhiều nhà thiết kế thấy HSL trực quan hơn RGB, vì nó cho phép màu sắc, độ bão hòa và độ nhẹ cho mỗi người được điều chỉnh độc lập. HSL cũng có thể giúp dễ dàng tạo ra một tập hợp các màu phù hợp (chẳng hạn như khi bạn muốn có nhiều sắc thái của một màu sắc). Tuy nhiên, sử dụng HSL để tạo ra các biến thể màu có thể tạo ra kết quả đáng ngạc nhiên, vì nó không đồng nhất về mặt nhận thức. Ví dụ, cả

/* These examples all specify the same color: a lavender. */
hsl(270,60%,70%)
hsl(270, 60%, 70%)
hsl(270 60% 70%)
hsl(270deg, 60%, 70%)
hsl(4.71239rad, 60%, 70%)
hsl(0.75turn, 60%, 70%)

/* These examples all specify the same color: a lavender that is 15% opaque. */
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 15%)
hsl(270 60% 50% / 0.15)
hsl(270 60% 50% / 15%)
3 và
/* These examples all specify the same color: a lavender. */
hsl(270,60%,70%)
hsl(270, 60%, 70%)
hsl(270 60% 70%)
hsl(270deg, 60%, 70%)
hsl(4.71239rad, 60%, 70%)
hsl(0.75turn, 60%, 70%)

/* These examples all specify the same color: a lavender that is 15% opaque. */
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 15%)
hsl(270 60% 50% / 0.15)
hsl(270 60% 50% / 15%)
4 đều có cùng độ nhẹ, mặc dù cái trước tối hơn nhiều so với cái sau.

Màu sắc HSL được thể hiện thông qua các ký hiệu

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

7 và
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

8 chức năng.

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

7 hoặc
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

8:
/* These examples all specify the same color: a lavender. */
hsl(270,60%,70%)
hsl(270, 60%, 70%)
hsl(270 60% 70%)
hsl(270deg, 60%, 70%)
hsl(4.71239rad, 60%, 70%)
hsl(0.75turn, 60%, 70%)

/* These examples all specify the same color: a lavender that is 15% opaque. */
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 15%)
hsl(270 60% 50% / 0.15)
hsl(270 60% 50% / 15%)
9 hoặc
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
0

/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
1 (HUE) là
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
2 của vòng tròn màu được đưa ra trong
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
3S,
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
4S,
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
5S hoặc
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
6S trong đặc tả màu CSS. Khi được viết dưới dạng
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
2 không đơn vị, nó được hiểu là độ, như được chỉ định trong đặc tả CSS Color Cấp 3. Theo định nghĩa, red = 0deg = 360deg, với các màu khác trải đều xung quanh vòng tròn, vì vậy màu xanh lá cây = 120deg, blue = 240deg, v.v. = 1Turn, v.v.

/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
9 (bão hòa) và
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
0 (độ sáng) là tỷ lệ phần trăm.
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 bão hòa hoàn toàn bão hòa, trong khi
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
2 hoàn toàn không bão hòa (màu xám).
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 Độ nhẹ có màu trắng, độ sáng
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
2 là màu đen và độ sáng
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
5 là "bình thường".saturation is completely saturated, while
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
2 is completely unsaturated (gray).
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 lightness is white,
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
2 lightness is black, and
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
5 lightness is "normal".

const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
3 (alpha) có thể là
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
2 giữa
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
8 và
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
9 hoặc
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
3, trong đó số
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
9 tương ứng với
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 (độ mờ hoàn toàn).

Mô hình màu HWB

Tương tự như mô hình màu HSL, mô hình màu HWB xác định một màu nhất định trong không gian màu SRGB theo các thành phần màu sắc, độ trắng và màu đen của nó.

Như với HSL, HWB có thể sử dụng trực quan hơn RGB. Một màu sắc được chỉ định theo cùng một cách, tiếp theo là độ trắng và màu đen, tương ứng, trong các giá trị phần trăm. Hàm này cũng chấp nhận một giá trị alpha.

Lưu ý: Không có hàm

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

03 riêng biệt như có HSL, giá trị alpha là một tham số tùy chọn, nếu nó không được chỉ định giá trị alpha là 1 (hoặc 100%) được sử dụng. Để chỉ định giá trị này, một dấu gạch chéo phía trước (
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

04) phải tuân theo giá trị màu đen trước khi giá trị alpha được chỉ định.
There is no separate
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

03 function as there is with HSL, the alpha value is an optional parameter, if it is not specified an alpha value of 1 (or 100%) is used. To specify this value a forward slash (
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

04) must follow the blackness value before the alpha value is specified.

Màu sắc HWB được thể hiện thông qua ký hiệu

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

9 chức năng.

Lưu ý: Hàm HWB không sử dụng dấu phẩy để phân tách các giá trị của nó như với các hàm màu trước đó. The HWB function does not use commas to separate its values as with previous color functions.

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

9:
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

07

Giống như HSL:

/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
1 (HUE) là
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
2 của vòng tròn màu được đưa ra trong
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
3S,
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
4S,
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
5S hoặc
/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)
6 trong đặc tả màu CSS. Khi được viết dưới dạng
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
2 không đơn vị, nó được hiểu là độ, như được chỉ định trong đặc tả CSS Color Cấp 3. Theo định nghĩa, red = 0deg = 360deg, với các màu khác trải đều xung quanh vòng tròn, vì vậy màu xanh lá cây = 120deg, blue = 240deg, v.v. = 1Turn, v.v.

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

16 (độ trắng) và
const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
2 (màu đen) là tỷ lệ phần trăm. Hai màu này trộn lẫn, vì vậy bạn sẽ cần
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
2 độ trắng và màu đen
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 để tạo ra màu đen. Và ngược lại
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 độ trắng và màu đen
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
2 cho màu trắng.
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
5 của cả hai giá trị hiển thị một màu xám giữa và bất kỳ biến thể nào khác là một sắc thái của màu sắc được chỉ định.whiteness and
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 blackness to produce the color black. And vice versa
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 whiteness and
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
2 blackness for the color white.
hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */
5 of both values renders a mid-grey and any other variations a shade of the hue specified.

const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});
3 (alpha), tùy chọn, có thể là
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
2 giữa
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
8 và
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
9 hoặc
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
3, trong đó số
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
9 tương ứng với
/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)
5 (độ mờ hoàn toàn). Khi chỉ định giá trị alpha, nó phải được đi trước với một dấu gạch chéo phía trước (
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

04).

Màu sắc hệ thống

Trong chế độ màu bắt buộc (có thể phát hiện với truy vấn phương tiện màu cưỡng bức), hầu hết các màu được giới hạn trong bảng màu do người dùng và trình duyệt xác định. Các màu hệ thống này được phơi bày bởi các từ khóa sau, có thể được sử dụng để đảm bảo rằng phần còn lại của trang tích hợp tốt với bảng màu bị hạn chế. Các giá trị này cũng có thể được sử dụng trong các bối cảnh khác, nhưng không được các trình duyệt hỗ trợ rộng rãi.

Các từ khóa trong danh sách sau được xác định bởi mô -đun màu CSS Cấp độ 4 Đặc điểm kỹ thuật:

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

31,
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

32,
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

33,
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

34,
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

35,
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

36,
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

37, ____.

Lưu ý: Lưu ý rằng các từ khóa này không nhạy cảm với trường hợp, nhưng được liệt kê ở đây với trường hợp hỗn hợp để đọc. Note that these keywords are case-insensitive, but are listed here with mixed case for readability.

Màu sắc phòng thí nghiệm

CSS Color 4 Giới thiệu màu phòng thí nghiệm. Màu sắc phòng thí nghiệm được chỉ định thông qua ký hiệu chức năng

<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />
1. Chúng không giới hạn trong một không gian màu cụ thể và có thể đại diện cho toàn bộ tầm nhìn của con người.

Mô hình màu LCH

CSS Color 4 Giới thiệu màu LCH. Màu sắc LCH được chỉ định thông qua ký hiệu chức năng

<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />
0. Chúng không giới hạn trong một không gian màu cụ thể và có thể đại diện cho toàn bộ tầm nhìn của con người.

Trong thực tế, LCH là dạng phân cực của phòng thí nghiệm. Nó thân thiện với con người hơn phòng thí nghiệm, vì các thành phần sắc độ và màu sắc của nó chỉ định các phẩm chất của màu sắc mong muốn, trái ngược với sự pha trộn. Nó tương tự như HSL theo cách đó, mặc dù nó đồng nhất về mặt nhận thức hơn nhiều. Không giống như HSL mô tả cả

/* These examples all specify the same color: a lavender. */
hsl(270,60%,70%)
hsl(270, 60%, 70%)
hsl(270 60% 70%)
hsl(270deg, 60%, 70%)
hsl(4.71239rad, 60%, 70%)
hsl(0.75turn, 60%, 70%)

/* These examples all specify the same color: a lavender that is 15% opaque. */
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 15%)
hsl(270 60% 50% / 0.15)
hsl(270 60% 50% / 15%)
4
/* These examples all specify the same color: a lavender. */
hsl(270,60%,70%)
hsl(270, 60%, 70%)
hsl(270 60% 70%)
hsl(270deg, 60%, 70%)
hsl(4.71239rad, 60%, 70%)
hsl(0.75turn, 60%, 70%)

/* These examples all specify the same color: a lavender that is 15% opaque. */
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 15%)
hsl(270 60% 50% / 0.15)
hsl(270 60% 50% / 15%)
3 là có cùng độ sáng, LCH (và phòng thí nghiệm) quy định chính xác các độ sáng khác nhau đối với chúng: cái trước (màu vàng) có L là 97,6 và sau (màu xanh) một L là 29.6. Do đó, LCH có thể được sử dụng để tạo ra các bảng màu trên các màu hoàn toàn khác nhau, với kết quả có thể dự đoán được. Xin lưu ý rằng màu sắc của LCH không giống như HSL Hue và LCH Chroma không giống như bão hòa HSL, mặc dù chúng có chung một số điểm tương đồng về khái niệm.

màu () màu

CSS Color 4 giới thiệu ký hiệu này. Các màu được chỉ định thông qua hàm

<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />
2 có thể chỉ định màu trong bất kỳ không gian màu được xác định trước, cũng như không gian màu tùy chỉnh, được xác định thông qua quy tắc
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

51.

Nội suy

Trong hình ảnh động và độ dốc, các giá trị

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

0 được nội suy trên mỗi thành phần màu đỏ, xanh lá cây và xanh dương của chúng. Mỗi thành phần được nội suy là một số điểm nổi thực sự. Lưu ý rằng việc nội suy các màu xảy ra trong không gian màu SRGBA được in alpha để ngăn chặn các màu xám bất ngờ xuất hiện. Trong hình ảnh động, tốc độ của nội suy được xác định bởi hàm thời gian.

Cân nhắc về khả năng tiếp cận

Một số người gặp khó khăn trong việc phân biệt màu sắc. Khuyến nghị WCAG 2.0 khuyên nên sử dụng màu sắc như là phương tiện duy nhất để truyền tải một thông điệp, hành động hoặc kết quả cụ thể. Xem màu sắc và độ tương phản màu để biết thêm thông tin.

Cú pháp chính thức

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

Ví dụ

Người kiểm tra giá trị màu

Trong ví dụ này, chúng tôi cung cấp

 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

53 và đầu vào văn bản. Nhập màu hợp lệ vào đầu vào khiến
 = 
|
currentcolor |

=
|
|
|
transparent

=
|
|
|
|
|
|
|
|
|

=
rgb( [ | none ]{3} [ / [ | none ] ]? ) |
rgb( [ | none ]{3} [ / [ | none ] ]? )

=
hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

=
lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

=
oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

=
color( [ / [ | none ] ]? )

=
|

=
|
|
none

=
|

=
[ | | none ]{3}

=
[ | | none ]{3}

=
srgb |
srgb-linear |
display-p3 |
a98-rgb |
prophoto-rgb |
rec2020

=
xyz |
xyz-d50 |
xyz-d65

53 áp dụng màu đó, cho phép bạn kiểm tra các giá trị màu của chúng tôi.

HTML

<div>div>
<hr />
<label for="color">Enter a valid color value:label>
<input type="text" id="color" />

CSS

div {
  width: 100%;
  height: 200px;
}

const inputElem = document.querySelector('input');
const divElem = document.querySelector('div');

function validTextColor(stringToTest) {
  if (stringToTest === "") { return false; }
  if (stringToTest === "inherit") { return false; }
  if (stringToTest === "transparent") { return false; }

  const image = document.createElement("img");
  image.style.color = "rgb(0, 0, 0)";
  image.style.color = stringToTest;
  if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  image.style.color = "rgb(255, 255, 255)";
  image.style.color = stringToTest;
  return image.style.color !== "rgb(255, 255, 255)";
}

inputElem.addEventListener('change', () => {
  if (validTextColor(inputElem.value)) {
    divElem.style.backgroundColor = inputElem.value;
    divElem.textContent = '';
  } else {
    divElem.style.backgroundColor = 'white';
    divElem.textContent = 'Invalid color value';
  }
});

Kết quả

Biến thể cú pháp RGB

Ví dụ này cho thấy nhiều cách trong đó một màu duy nhất có thể được tạo với các cú pháp màu RGB khác nhau.

/* These syntax variations all specify the same color: a fully opaque hot pink. */

/* Hexadecimal syntax */
#f09
#F09
#ff0099
#FF0099

/* Functional syntax */
rgb(255,0,153)
rgb(255, 0, 153)
rgb(255, 0, 153.0)
rgb(100%,0%,60%)
rgb(100%, 0%, 60%)
rgb(100%, 0, 60%) /* ERROR! Don't mix numbers and percentages. */
rgb(255 0 153)

/* Hexadecimal syntax with alpha value */
#f09f
#F09F
#ff0099ff
#FF0099FF

/* Functional syntax with alpha value */
rgb(255, 0, 153, 1)
rgb(255, 0, 153, .5)
rgb(255, 0, 153, 0.5)
rgb(255, 0, 153, 100%)

/* Whitespace syntax */
rgb(255 0 153 / 1)
rgb(255 0 153 / 100%)

/* Functional syntax with floats value */
rgb(255, 0, 153.6, 1)
rgb(2.55e2, 0e0, 1.53e2, 1e2%)

Biến thể minh bạch RGB

/* Hexadecimal syntax */
#3a30                    /*   0% opaque green */
#3a3f                    /* full opaque green */
#33aa3300                /*   0% opaque green */
#33aa3380                /*  50% opaque green */

/* Functional syntax */
rgba(51, 170, 51, 0.1)    /*  10% opaque green */
rgba(51, 170, 51, 0.4)    /*  40% opaque green */
rgba(51, 170, 51, 0.7)    /*  70% opaque green */
rgba(51, 170, 51,   1)    /* full opaque green */

/* Whitespace syntax */
rgba(51 170 51 / 0.4)    /*  40% opaque green */
rgba(51 170 51 / 40%)    /*  40% opaque green */

/* Functional syntax with floats value */
rgba(51,    170,   51.6,  1)
rgba(5.1e1, 1.7e2, 5.1e1, 1e2%)

Biến thể cú pháp HSL

/* These examples all specify the same color: a lavender. */
hsl(270,60%,70%)
hsl(270, 60%, 70%)
hsl(270 60% 70%)
hsl(270deg, 60%, 70%)
hsl(4.71239rad, 60%, 70%)
hsl(0.75turn, 60%, 70%)

/* These examples all specify the same color: a lavender that is 15% opaque. */
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 0.15)
hsl(270, 60%, 50%, 15%)
hsl(270 60% 50% / 0.15)
hsl(270 60% 50% / 15%)

Biến thể cú pháp HWB

/* These examples all specify varying shades of a lime green. */
hwb(90 10% 10%)
hwb(90 50% 10%)
hwb(90deg 10% 10%)
hwb(1.5708rad 60% 0%)
hwb(0.25turn 0% 40%)

/* Same lime green but with an alpha value */
hwb(90 10% 10% / 0.5)
hwb(90 10% 10% / 50%)

Màu sắc bão hòa hoàn toàn

Màu xanh nhạt và tối hơn

Greens bão hòa và không bão hòa

Biến thể minh bạch HSL

hsla(240, 100%, 50%, 0.05)    /*   5% opaque blue */
hsla(240, 100%, 50%, 0.4)     /*  40% opaque blue */
hsla(240, 100%, 50%, 0.7)     /*  70% opaque blue */
hsla(240, 100%, 50%, 1)       /* full opaque blue */

/* Whitespace syntax */
hsla(240 100% 50% / 0.05)     /*   5% opaque blue */

/* Percentage value for alpha */
hsla(240 100% 50% / 5%)       /*   5% opaque blue */

Thông số kỹ thuật

Sự chỉ rõ
Thông số kỹ thuật không xác định # Color-syntax
# color-syntax

Tính tương thích của trình duyệt web

Bảng BCD chỉ tải trong trình duyệt

Xem thêm

  • Thuộc tính
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    55 cho phép bạn xác định tính minh bạch ở cấp phần tử.
  • Một số thuộc tính phổ biến sử dụng loại dữ liệu này:
    div {
      width: 100%;
      height: 200px;
    }
    
    0,
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    57,
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    58,
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    59,
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    60,
     = 
    |
    currentcolor |

    =
    |
    |
    |
    transparent

    =
    |
    |
    |
    |
    |
    |
    |
    |
    |

    =
    rgb( [ | none ]{3} [ / [ | none ] ]? ) |
    rgb( [ | none ]{3} [ / [ | none ] ]? )

    =
    hsl( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    hwb( [ | none ] [ | none ] [ | none ] [ / [ | none ] ]? )

    =
    lab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    lch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    oklab( [ | | none ] [ | | none ] [ | | none ] [ / [ | none ] ]? )

    =
    oklch( [ | | none ] [ | | none ] [ | none ] [ / [ | none ] ]? )

    =
    color( [ / [ | none ] ]? )

    =
    |

    =
    |
    |
    none

    =
    |

    =
    [ | | none ]{3}

    =
    [ | | none ]{3}

    =
    srgb |
    srgb-linear |
    display-p3 |
    a98-rgb |
    prophoto-rgb |
    rec2020

    =
    xyz |
    xyz-d50 |
    xyz-d65

    61
  • Áp dụng màu cho các phần tử HTML bằng CSS

Màu sắc CSS hợp lệ là gì?

Các tiêu chuẩn W3C HTML và CSS chỉ liệt kê 16 tên màu hợp lệ: Aqua, Black, Blue, Fuchsia, Grey, Green, Lime, Maroon, Navy, Olive, Purple, Red, Breat, Teal, White và Yellow.aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow.

Có bao nhiêu màu CSS?

CSS cung cấp 145 tên màu, từ cơ bản nhất (đen, trắng, cam, vàng, xanh) đến cụ thể hơn (Lawngreen, Orchid, Crimson,).145 colors names, from the most basic (black, white, orange, yellow, blue…) to the more specific (lawngreen, orchid, crimson…).

CSS là gì?

Các bảng kiểu xếp tầng (CSS) là ngôn ngữ biểu định kiểu được sử dụng để mô tả bản trình bày của một tài liệu được viết bằng HTML hoặc XML (bao gồm các phương ngữ XML như SVG, MathML hoặc XHTML).a stylesheet language used to describe the presentation of a document written in HTML or XML (including XML dialects such as SVG, MathML or XHTML).