English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS reference manual

CSS @rules

CSS attribute大全

CSS Color Values

There are several methods to define color values in CSS.

color keywords

Color keywords are case-insensitive identifiers that represent specific colors, such as red, green, blue, yellow, black, and so on.

  h1 {
   color:  red;
  }
  p {
   background-color:  yellow;
  }
Test and see‹/›

Warning:Support for color keywords varies between browsers, so for safety, it is best to use hexadecimal or functional symbols.

viewcolor keywordscomplete list

Transparent color keywords

The keyword 'transparent' represents a completely transparent color.

该关键字可以视为透明黑色的简写形式rgba(0,0,0,0),也是它的计算值。

  h1 {
   color: transparent;
  }
  p {
   background-color: transparent;
  }
Test and see‹/›

Note: CSS 2The keyword can be considered as a shorthand form of rgba(0,0,0,0), which is also its calculated value.1color: transparent;background-and.only allow two properties,-andborder3color

Accepts the transparent keyword. However, CSS

Extended color values to include the transparent keyword to allow its use with all properties that accept color values.

RGB color values

RGB (Red Green Blue) color model is the most commonly used method to define color values in CSS. Colors can be defined using the RGB model in two ways:-9Hexadecimal notation

The hexadecimal notation RGB value # is composed of three or six hexadecimal characters (0

  h1 {
   ,af)组成。8When using six-digit symbols (#rrggbb), the first pair (rr) represents the red value, the second pair (gg) represents the green value, and the last pair (bb) represents the blue value.
  }
  p {
   background-color: #f880;
  }
Test and see‹/›

color: #ff00;3Hint:33ff, but the two values represent the same color. f can be expanded to #00

Function notation

In function notation, RGB values are specified as: rgb(red, green, blue). Each parameter (red, green, and blue) defines the intensity of the color, which can be an integer value (from 0 to255) or a percentage value (from 0% to100%).

integer values255Corresponds to100%, in hexadecimal notation f or ff: for example, rgb(0,255,255) = rgb(0%,100%,100%) = #0ff, all values represent the same color, that is, aqua. Spaces are allowed around the values.

  h1 {
   color: rgb(0,255,255);
  }
  p {
   background-color: rgb(0%,100%,100%);
  }
Test and see‹/›

A value of 0 or 0% indicates that a specific color value does not exist, whereas a value255,100% and f or ff indicate that the color value is completely present.

Note:Out of valid range (0-255or 0%-10The value of (0%)will be automatically clipped or changed to a range supported by the device.

View more aboutCSS3Colortutorials to learn about new function symbols (such as) rgba(), hsl(), and hsla() for defining color values information.