CSS colors are stuck in the sRGB era
CSS arrived in 1996, when most monitors were far from capable. Its color formats — RGB, HSL, and hexadecimal — were built for those displays and all fall inside the sRGB colorspace. Most newer devices ship a wide-gamut display: a gamut being the range of colors a screen can show, a wide-gamut screen being one that exceeds sRGB. Such screens use the Display P3 colorspace. (Rec.2020 is larger still, but it's rare enough to ignore for now.) As Lea Verou of the CSS working group put it, "Our websites are washed out because screens advanced faster than CSS Color did." Reaching the full range most screens can now render requires the newer CSS formats: lab, lch, or display-p3.
Panic's site and the Playdate marketing site both demonstrate the effect, using display-p3 for strikingly vibrant colors.

The Pen below shows what sRGB leaves out. Inner boxes hold a color beyond the sRGB gamut; outer boxes show the same color clamped to sRGB — the nearest equivalent a browser can render without display-p3, lab, or lch. (Support is currently limited to Safari.) The color picker in Safari Technology Preview also flags which colors fall outside the sRGB gamut.

New syntax for familiar functions
Before tackling lab(), lch(), and the color() function, note the updated rgb() and hsl() syntaxes, supported everywhere except Internet Explorer.
| Type | Old Syntax | New Syntax |
|---|---|---|
| RGB | rgb(0, 128, 255) | rgb(0 128 255) |
| RGBa | rgba(0, 128, 255, 0.5) | rgb(0 128 255 50%) |
| HSL | hsl(198, 28%, 50%) | hsl(198 28% 50%) |
| HSLa | hsla(198, 28%, 0.5) | hsl(198deg 28% 50% / 50%) |
The old syntax comma-separated every value: rgb(200, 100, 20);. Commas are no longer required, so rgb(200 100 20); is valid. Transparency now takes the form rgb(200 100 20 / 50%) instead of rgba() or hsla(). The new syntax offers no real benefit on its own, but it matches how lch(), lab(), and color() are written.
| Type | Syntax |
|---|---|
| Lab | lab(56.29% -10.93 16.58 / 50%) |
| color() | color(sRGB 0 0.5 1 / 50%) |
| LCH | lch(56.29% 19.86 236.62 / 50% |
Those three functions always use space-separated numbers (commas are disallowed), with transparency expressed as a forward slash followed by a percentage.
The color() function and display-p3
color() lets you name a colorspace instead of defaulting to the sRGB space used by rgb(), hsl(), and hex. Wide-gamut color requires display-p3, which takes three numeric values for the red, green, and blue channels: 1 0 0 is full red, 0 0 1 full blue, and 0 1 0 full green.
background-color: color(display-p3 1 0 0.331); /* vibrant pink color */
At the time of writing, display-p3 is the only route to high-gamut colors, supported in Safari since 2017. lab() and lch() will be preferable once implemented; Chrome and Safari are working on it. Lea Verou's take:
display-p3is not perceptually uniform, and is difficult to create variants (lighter or darker, more or less vivid etc) by tweaking its parameters. Furthermore, it's a short-term solution. It works now, because screens that can display a wider gamut than P3 are rare. Once hardware advances again,color(display-p3 ...)will have the same problem as sRGB colors have today. LCH and Lab are device independent, and can represent the entire gamut of human vision so they will work regardless of how hardware advances.
Why HSL isn't enough
HSL has long been framed as more intuitive than RGB or hex. Chris Coyier, in 2015:
The real appeal of HSLa is that it makes more intuitive sense what changing the values will do to the color. Increasing the second value will increase the saturation of that color. Decreasing the third value will decrease the lightness of that color. That makes creating your own color variations on the fly way easier.
But HSL's lightness calculation doesn't match human perception. It treats hsl(240deg 100% 50%) and hsl(60deg 100% 50%) as equally light at 50%; to the eye, the blue reads darker. Brian Kardell:
Doing things like mixing colors, lightening, darkening, can be done well only if they include a sense of how our eyes really work rather than how machines like to think about storing and displaying.
Lea Verou's visual example shows Lab/LCH outperforming HSL, with her note:
A trick for aesthetically pleasing gradients of the same color at different lightnesses is to convert to Lab, vary the L instead, and then convert back to HSL/RGB.
Lab and LCH both build on the CIELAB colorspace, designed to align with human vision: two colors given the same lightness value appear equally light regardless of hue.
Lab
background-color: lab(40% 83 -104); /* a shade of purple */
In lab(), L is lightness, written as a percentage (it can reach 400% for extra-bright white, though it generally sits between 0% and 100%). A and B are color channels standing for no word in particular: A runs from green (negative) to red (positive), B from blue (negative) to yellow (positive). Lightness is easy to grasp; the red/green and blue/yellow axes are not, which makes LCH the friendlier option.
LCH
background-color: lch(69% 56 244); /* a shade of blue */
lch() is the most human-readable of the new values. L is lightness, working exactly as in Lab; C is chroma; H is hue. Chroma is roughly analogous to saturation, though it can also be read as color intensity or vibrancy. Unlike the other new formats, you can predict the effect of changing each value — much as with HSL. The LCH color picker is the quickest way to get a feel for it.

Fallbacks and feature detection
Two kinds of support matter: browsers understanding the new color values, and screens being able to show them. Falling back to the closest sRGB match for browsers without color-function support works just like any other fallback declaration:
.pink-text {
color: rgb(255, 0, 79); /* Will be used as a fallback */
color: color(display-p3 1 0 0.331); /* Will be used if supported */
}
If the browser doesn't understand the second line above, it ignores it, and the rgb() value wins through the cascade. Writing two declarations per color gets tedious, so CSS variables help. This example uses @supports to test whether the browser handles color functions:
/* https://webkit.org/blog/10042/wide-gamut-color-in-css-with-display-p3/ */
:root {
--bright-green: rgb(0, 255, 0);
}
/* Display-P3 color, when supported. */
@supports (color: color(display-p3 1 1 1)) {
:root {
--bright-green: color(display-p3 0 1 0);
}
}
header {
color: var(--bright-green);
}
Where a color is central to the design, a background-image is another option, since most browsers support high-gamut colors in images.
@supports not (color: color(display-p3 1 0 0.331)) {
@supports (-webkit-background-clip: text){
.pink-text {
background-image: url("pink-P3.png");
background-size: cover;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
}
}
.pink-text {
color: rgb(255, 0, 79);
color: color(display-p3 1 0 0.331);
}
A PostCSS plugin converts lab() and lch() to rgb(); for Sass users there is Blend, a tool from Miriam Suzanne.
Detecting what the screen can show
@supports reports whether the browser understands the syntax, not whether the user's monitor can display the color. A display without high-gamut support simply renders the nearest sRGB equivalent, so every monitor is covered without extra code.
To pick the fallback yourself instead of letting the browser calculate it, color() accepts a second color value. That path requires browser support for color(), and support for the second argument hasn't landed in any browser yet.
background-color: color(display-p3 1 0 0.331, #f54281);
For finer control, the Media Queries Level 4 spec adds a color-gamut media query.
@media (color-gamut: p3) {
/* Code to run only on hardware that supports P3 color */
}
The example checks for P3, but rec-2020 — wider than P3 — can be tested too. Screens supporting rec-2020 are currently minimal and limited to high-definition televisions, so it won't be a common target soon. sRGB can also be checked, though almost all monitors qualify today. The color-gamut query itself has reasonably good browser support at the time of writing.
A note on the dynamic-range query
The Safari 13.1 release notes use the dynamic-range media query to conditionally apply a P3 color; that apparently isn't a good use case. Florian Rivoal, editor of the Media Queries specification, explains the query is meant for video:
[S]ome screen can show ultra-bright lights for brief amounts of times, that are used in videos for things like sparks, direct sunlight, etc. This is much brighter than white, and isn't meant to be used with static images. It would be uncomfortable, and would also damage the screen.
Design tooling lags behind
Figma, Sketch, and XD don't currently support the Lab, LCH, or P3 colorspaces. Photoshop, by contrast, does offer a Lab color picker.



