Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Functions

The color() function

Reference for the CSS color() function: choose a color space such as srgb, display-p3 or rec2020, write channel values, use alpha, and detect wide gamut.

The color() function lets you write a color in a named color space you choose. Its main use is reaching colors outside the sRGB gamut, for example with display-p3, which most recent phones, tablets and laptops can show. On such screens, color(display-p3 1 0 0) is a noticeably more intense red than rgb(255 0 0).

CSS
.hero {
  background: #ff3b30; /* fallback */
  background: color(display-p3 1 0.23 0.19);
}

Try it

sRGB red next to Display P3 red

Syntax

CSS
color(<colorspace> c1 c2 c3)
color(<colorspace> c1 c2 c3 / A)
color(from <color> <colorspace> c1 c2 c3 / A)

Syntax and arguments

Argument Description
srgb, srgb-linear The sRGB space with its usual gamma curve, or with linear light values.
display-p3 The wide-gamut space used by many modern displays.
a98-rgb, prophoto-rgb, rec2020 Other RGB spaces with progressively larger gamuts.
xyz, xyz-d50, xyz-d65 The CIE XYZ space with a D50 or D65 white point; xyz means xyz-d65.
c1 c2 c3 Three channel values, numbers (usually 0โ€“1) or percentages, in the order of the space's channels.
A Optional alpha, number or percentage.

Usage notes

  • Always give a fallback. Declare an sRGB color first, then the color() version; browsers that do not understand the second ignore it.
  • Detect gamut in CSS. Use @media (color-gamut: p3) to apply wide-gamut colors only where the screen supports them.
  • Out-of-gamut values are mapped. A display that cannot show the color shows a close one instead; you will not get an error.
  • Channels are not hex. Values are fractions, not 0โ€“255.
  • Mixing and gradients. color-mix() and gradients accept color() values and can interpolate in these spaces.
  • Perceptual spaces such as oklch() have their own functions; color() is for RGB and XYZ spaces.

Browser support

Supported in current versions of all major browsers. Wide-gamut results depend on the display too. Check a compatibility table for older browsers.