The <color>CSSdata type represents a color. A <color> may also include an alpha-channeltransparency value, indicating how the color should composite with its background.
Note: Although <color> 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.
The currentcolor keyword represents the value of an element's color property. This lets you use the color value on properties that do not receive it by default.
If currentcolor is used as the value of the color property, it instead takes its value from the inherited value of the color property.
html
<divstyle="color: blue;border: 1px dashed currentcolor;">
The color of this text is blue.
<divstyle="background: currentcolor;height:9px;"></div>
This block is surrounded by a blue border.
</div>
Missing color components
Each component of any CSS color functions - except for those using the legacy comma-separated syntax - can be specified as the keyword none to be a missing component.
Explicitly specifying missing components is useful in color interpolation for cases where you would like to interpolate some color components but not others. For all other purposes, a missing component will effectively have a zero value in an appropriate unit: 0, 0%, or 0deg. For example, the following colors are equivalent when used outside of interpolation:
css
/* These are equivalent */color:oklab(50% none -0.25);color:oklab(50% 0 -0.25);/* These are equivalent */background-color:hsl(none 100% 50%);background-color:hsl(0deg 100% 50%);
When interpolating <color> values, they are first converted to a given color space, and then each component of the computed values are interpolated linearly, with interpolation's speed being determined by the easing function in transitions and animations. The interpolation color space defaults to Oklab, but can be overridden through <color-interpolation-method> in some color-related functional notations.
Interpolation with missing components
Interpolating colors in the same space
When interpolating colors that are exactly in the interpolation color space, missing components from one color are replaced with existing values of the same components from the other color. For example, the following two expressions are equivalent:
Note: If a component is missing from both colors, this component will be missing after the interpolation.
Interpolating colors from different spaces: analogous components
If any color to be interpolated is not in the interpolation color space, its missing components are transferred into the converted color based on analogous components of the same category as described in the following table:
Category
Analogous components
Reds
R, X
Greens
G, Y
Blues
B, Z
Lightness
L
Colorfulness
C, S
Hue
H
a
a
b
b
For example:
X (0.2) in color(xyz 0.2 0.1 0.6) is analogous to R (50%) in rgb(50% 70% 30%).
H (0deg) in hsl(0deg 100% 80%) is analogous to H (140) in oklch(80% 0.1 140).
Using Oklch as the interpolation color space and the two colors below as an example:
css
lch(80% 30 none)color(display-p3 0.7 0.5 none)
the preprocessing procedure is:
Replace the missing components in both colors with a zero value:
css
lch(80% 30 0)color(display-p3 0.7 0.5 0)
Convert both colors into the interpolation color space:
Some people have difficulty distinguishing colors. The WCAG 2.2 recommendation strongly advises against using color as the only means of conveying a specific message, action, or result. See color and color contrast for more information.
In this example we provide a <div> and a text input. Entering a valid color into the input causes the <div> to adopt that color, allowing you to test our color values.
HTML
html
<div></div><hr/><labelfor="color">Enter a valid color value:</label><inputtype="text"id="color"/>
Result
Fully saturated sRGB colors
This example shows fully saturated sRGB colors in the sRGB color space.
15
10.1–15Only supports display-p3 and srgb predefined color profiles.
111
111
113
No
15
10.3–15Only supports display-p3 and srgb predefined color profiles.
22.0
color-contrast
No
No
No
No
No
15
No
No
No
No
15
No
color-mix
111
111
113
No
97
16.2
111
111
113
No
16.2
22.0
currentcolor
1
12
1.5
9
9.5
4
37
18
4
14
3.2
1.0
hsl
1
12
1
9
9.5
3.1
≤37
18
4
10.1
2
1.0
hsla
1
12
3
9
10
3.1
≤37
18
4
10.1
2
1.0
hwb
101
101
96
No
87
15
101
101
96
70
15
19.0
lab
111
111
113
No
97
15
111
111
113
No
15
22.0
lch
111
111
113
No
97
15
111
111
113
No
15
22.0
light-dark
No
No
120
No
No
No
No
No
120
No
No
No
named-color
1
12
1
3Internet Explorer 8 and later support gray color keywords spelled with an e (grey, darkgrey, darkslategrey, dimgrey, lightgrey, and lightslategrey). Internet Explorer 3 to Internet Explorer 7 only support the keywords spelled with a (gray, darkgray, darkslategray, dimgray, lightgray, and lightslategray).
3.5
1
≤37
18
4
10.1
1
1.0
oklab
111
111
113
No
97
15.4
111
111
113
No
15.4
22.0
oklch
111
111
113
No
97
15.4
111
111
113
No
15.4
22.0
rgb
1
12
1
4
3.5
1
≤37
18
4
10.1
1
1.0
rgb_hexadecimal_notation
1
12
1
3
3.5
1
≤37
18
4
10.1
1
1.0
rgba
1
12
3
9
10
3.1
≤37
18
4
10.1
2
1.0
system-color
1
12
1
3
3.5
1
≤37
18
4
10.1
1
1.0
transparent
1
12
3
9
10
3.1
37
18
4
10.1
2
1.0
See also
opacity: the property defining transparency at the element level
<hue>: the data type representing the hue angle of a color