color() CSS Function
The color() function defines a color in a named color space, such as color(display-p3 1 0 0), for colors beyond the sRGB range.
Description
The color() CSS function lets you specify a color in a particular, named color space, rather than in the default sRGB space used by functions such as rgb() and hsl(). Its main purpose is to give access to wide-gamut color spaces such as display-p3 and rec2020, which can show more vivid colors than sRGB on modern screens. The result is a normal <color> value, so it can be used with any property that accepts a color, including color, background-color and border-color.
The first argument is the name of the color space. For the RGB-based spaces (srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb and rec2020) the next three values are the red, green and blue channels, written as numbers from 0 to 1 or as percentages. For the XYZ spaces (xyz, xyz-d50 and xyz-d65) the three values are the X, Y and Z coordinates. An optional alpha value can be added after a slash. If the screen cannot show the requested color, the browser maps it to the closest color it can display.
color() also supports relative color syntax with the from keyword, which converts an existing color into the chosen space so you can adjust individual channels.
/* A vivid red that sRGB cannot represent */
.badge {
background-color: #ff0000; /* fallback */
background-color: color(display-p3 1 0 0);
}
/* Semi-transparent color in sRGB */
.overlay {
background-color: color(srgb 0 0 0 / 0.5);
}
/* Relative color: reduce the green channel of a brand color */
.accent {
color: color(from var(--brand) srgb r calc(g * 0.5) b);
}
Because older browsers do not understand color(), it is good practice to declare an sRGB fallback first, or to wrap wide-gamut styles in @supports (color: color(display-p3 1 0 0)).
Interactive Demo
Syntax
color() = color( [ from <color> ]? <colorspace-params> [ / [ <alpha-value> | none ] ]? )
<colorspace-params> = <predefined-rgb> [ <number> | <percentage> | none ]{3}
| <xyz-space> [ <number> | <percentage> | none ]{3}
<predefined-rgb> = srgb | srgb-linear | display-p3 | a98-rgb | prophoto-rgb | rec2020
<xyz-space> = xyz | xyz-d50 | xyz-d65
Values
- colorspaceThe name of the color space: srgb, srgb-linear, display-p3, a98-rgb, prophoto-rgb, rec2020, xyz, xyz-d50 or xyz-d65.
- c1 c2 c3The three channel values. For RGB spaces these are red, green and blue as a <number> from 0 to 1 or a <percentage>. For XYZ spaces they are the X, Y and Z coordinates. The keyword none can be used for a missing channel.
- alphaOptional. An <alpha-value> after a slash (/) that sets the opacity, from 0 (transparent) to 1 (opaque).
- from <color>Optional. Starts relative color syntax, converting the given color into the chosen color space so its channels can be referenced as r, g, b (or x, y, z) and alpha.
Example
Browser Support
The following information will show you the current browser support for the CSS color() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





