Color Spaces and Gamuts: lab(), lch(), oklab(), oklch() and color()
Wide-gamut color in CSS: gamuts and color spaces, perceptual lightness, lab() and lch(), oklab() and oklch() with their ranges, the color() function, out-of-gamut mapping, gamut media queries, fallbacks, and building palettes in oklch().
kvi5hnuCode Sprout team member10 min readOn this page
Hex, rgb(), hsl() and hwb() (article 31) all describe colors in sRGB, the color range of screens from the 1990s. Most phones and laptops now show more vivid colors than that, and CSS has notations that can use them. These notations are also better for designing: their lightness matches what people see.
Gamuts and color spaces
A gamut is a range of colors: the colors a screen can show, or a notation can describe. A color space is a way of arranging and numbering colors, like coordinates on a map. Several color spaces can cover the same gamut.

| Gamut | Covers | Typical screens |
|---|---|---|
| sRGB | the classic web colors | every screen |
| Display P3 | about a third more area on the chart, mostly more vivid greens, and also reds and oranges | most modern phones, tablets and laptops |
| Rec. 2020 | much more | some HDR monitors and TVs |
Colors written in sRGB notations can never be more vivid than sRGB, even on a P3 screen. To use the extra colors, you need a notation that reaches beyond it.
Perceptual lightness
The other problem with hsl() is that its numbers don't match perception. Every color below has hsl() lightness 50%, but yellow looks far lighter than blue. In oklch(), colors with the same lightness value look equally light:
body { font: 600 0.85rem system-ui, sans-serif; }
.row { display: flex; gap: 6px; margin-bottom: 0.4rem; }
.row span { flex: 1; height: 3rem; border-radius: 6px; }
.hsl span:nth-child(1) { background: hsl(25 90% 50%); }
.hsl span:nth-child(2) { background: hsl(60 90% 50%); }
.hsl span:nth-child(3) { background: hsl(140 90% 50%); }
.hsl span:nth-child(4) { background: hsl(200 90% 50%); }
.hsl span:nth-child(5) { background: hsl(245 90% 50%); }
.hsl span:nth-child(6) { background: hsl(300 90% 50%); }
.ok span:nth-child(1) { background: oklch(65% 0.17 45); }
.ok span:nth-child(2) { background: oklch(65% 0.13 100); }
.ok span:nth-child(3) { background: oklch(65% 0.17 145); }
.ok span:nth-child(4) { background: oklch(65% 0.12 230); }
.ok span:nth-child(5) { background: oklch(65% 0.17 275); }
.ok span:nth-child(6) { background: oklch(65% 0.2 330); }

The grayscale rows remove hue and leave only lightness. The hsl() row turns into a jumble of light and dark, while the oklch() row is almost one even gray.
That matters for design systems: with oklch(), a "500" shade of every hue has similar contrast against white, and changing the hue of a button doesn't suddenly make its text unreadable.
oklch()
oklch(L C H / alpha) describes a color by lightness, chroma and hue:
| Channel | Range | Meaning |
|---|---|---|
| L | 0% to 100%, or 0 to 1 | perceived lightness, black to white |
| C | 0 up to about 0.37 in practice (100% = 0.4) | chroma, how colorful: 0 is gray |
| H | 0 to 360, as a number or angle | hue angle |
:root {
--brand: oklch(45% 0.12 45); /* a deep rust */
--brand-light: oklch(92% 0.04 45); /* the same hue, very light */
--success: oklch(55% 0.13 150);
--info: oklch(55% 0.13 250); /* same lightness and chroma: a matching set */
}
- The hues differ from
hsl(): roughly red at 25–30, orange at 50–70, yellow at 90–110, green at 140–150, cyan at 195, blue at 260–265 and magenta at 330. - Chroma has no fixed maximum. How much is displayable depends on the lightness and hue: a light yellow can be very vivid, a light blue can't. In sRGB, chroma tops out around 0.32 (for pure blue and magenta), and P3 reaches about 0.37.
- Lightness is clamped to 0–100%, and negative chroma to 0.
oklch() has become the most popular notation for design tokens: lightness controls contrast, chroma controls vividness, and hue stays stable when you change the other two. Tools such as browser DevTools color pickers convert any color to oklch() and show where the sRGB boundary is.
oklab()
oklab(L a b) is the same color space with rectangular coordinates: lightness, then a (green to red, about -0.4 to 0.4) and b (blue to yellow, about -0.4 to 0.4). It's less intuitive to write, but excellent for mixing and gradients: interpolating in Oklab gives smooth results without the grayish middle of sRGB gradients. It's the default color space for color-mix() when none is given, and for gradients and transitions between modern colors such as oklch() (articles 33 and 51). Between legacy sRGB notations, such as hex and rgb(), gradients still interpolate in sRGB for compatibility, unless you add in oklab.
lab() and lch()
lab() and lch() are the older CIE Lab color spaces that Oklab improves on. They work the same way, with different ranges: lightness 0 to 100, a and b about -125 to 125, and chroma up to about 150. Their main flaw is a hue shift in blues: making a blue lighter in lch() turns it purple. Prefer oklch() and oklab() unless you match values from print or design software that use Lab.
color()
color() names a color space explicitly, and gives its channels:
.vivid-red { color: color(display-p3 1 0 0); } /* the reddest red a P3 screen can show */
.flat { color: color(srgb 0.54 0.23 0.07); }
| Space | Use |
|---|---|
srgb, srgb-linear | standard sRGB, or its linear-light version |
display-p3-linear | linear-light version of Display P3, Baseline since January 2026 |
display-p3 | Display P3 |
rec2020 | Rec. 2020 |
a98-rgb, prophoto-rgb | spaces from photography and print |
xyz, xyz-d50, xyz-d65 | the CIE XYZ space that all others convert through |
Channels in the RGB spaces go from 0 to 1. color(display-p3 ...) is the direct way to use a P3 color picked in a design tool. For hand-written colors, oklch() is usually easier.
Out-of-gamut colors
oklch(), oklab(), lab() and lch() can describe colors that no screen can show, and color() values beyond 0–1 also leave their gamut. The computed value keeps them as written; the browser maps them to the nearest displayable color only when it paints. On an sRGB screen, a P3 color appears as a close sRGB color, which is a natural fallback.
The mapping isn't always graceful for colors far outside the gamut: it can shift the hue or lightness. Keep chroma within what P3 screens can show, roughly 0.37 at most and less for dark or light colors, and check colors in a picker that shows gamut boundaries.
Detecting gamuts
Media queries test the screen's capabilities:
.badge { background: oklch(60% 0.15 145); }
@media (color-gamut: p3) {
.badge { background: oklch(60% 0.25 145); } /* more vivid where possible */
}
@media (dynamic-range: high) { /* HDR-capable screens */ }
color-gamut accepts srgb, p3 and rec2020. You often don't need it: since out-of-gamut colors are mapped automatically, writing the vivid color once is usually fine.
Fallbacks
oklch(), oklab(), lab(), lch() and color() are Baseline widely available since November 2025, so most projects can use them directly. If you support older browsers, declare an sRGB color first:
.button {
background: #8a3b12;
background: oklch(45% 0.12 45); /* ignored where unsupported */
}
For custom properties, a fallback declaration doesn't help, because the invalid value only fails when it's used (article 27). Wrap the token definitions in @supports (color: oklch(0 0 0)) instead.
Building a palette in oklch()
A practical method:
- Pick a hue for each color family: brand, neutral, success, warning, danger.
- Make a lightness scale shared by all families, for example 97%, 92%, 84%, 74%, 63%, 53%, 45%, 37%, 28%, 20%.
- Choose chroma per step: lower at the very light and very dark ends, where screens can't show much chroma, and highest in the middle.
- Give neutrals a tiny chroma in the brand hue, such as
0.01, which looks warmer or cooler than pure gray.
:root {
--brand-hue: 45;
--brand-100: oklch(95% 0.03 var(--brand-hue));
--brand-300: oklch(80% 0.09 var(--brand-hue));
--brand-500: oklch(60% 0.14 var(--brand-hue));
--brand-700: oklch(45% 0.12 var(--brand-hue));
--brand-900: oklch(28% 0.07 var(--brand-hue));
--gray-100: oklch(96% 0.006 var(--brand-hue));
--gray-700: oklch(42% 0.01 var(--brand-hue));
}
Because lightness is perceptual, the same step number in each family gives similar contrast, so text colors that work on --brand-100 also work on --success-100. Article 35 shows how to check contrast, and article 33 how to derive steps automatically.

Read down any column: the hues change but the lightness doesn't, so one text color works on that step for every family.
What's current
oklch(),oklab(),lab(),lch()andcolor()are Baseline widely available since November 2025.- Gradients and transitions between modern colors interpolate in Oklab by default, while gradients between hex or
rgb()colors still use sRGB unless you writein oklab(articles 33 and 51). color-gamutanddynamic-rangemedia queries work in all browsers.
Common questions
Is oklch() safe to use?
Yes, in every current browser. It's been supported since 2023 and is Baseline widely available.
Why does my vivid oklch() color look the same as a duller one on my screen?
Your screen may be sRGB, so colors beyond it are mapped to the nearest sRGB color. On a P3 screen, the vivid one shows its full chroma.
What's the difference between lch() and oklch()?
Both use lightness, chroma and hue, but Oklch is a newer, more accurate model: hues stay stable when lightness changes, and the number ranges differ. Use oklch().
How do I convert my hex colors to oklch()?
In browser DevTools, open the color picker for a color and switch its format. The conversion is rounded to a few decimals, so the color looks identical.
What's the maximum chroma? There's no fixed one: it depends on the lightness, the hue and the gamut. For sRGB, about 0.32 is the most for blue and magenta, and much less for others, such as about 0.15 for cyan. A gamut-aware picker shows the limit.
Summary
- A gamut is a range of colors; a color space is a way of numbering them. sRGB notations can't describe P3 or Rec. 2020 colors.
oklch(L C H)uses perceptual lightness, chroma and hue. Equal lightness looks equally light across hues.oklab()is the same space in rectangular coordinates, and the default for mixing and gradients.lab()andlch()are older and shift some hues. Prefer the Ok versions.color()names a space explicitly, such asdisplay-p3orrec2020.- Out-of-gamut colors are mapped to displayable ones when painted. Keep chroma moderate.
color-gamutanddynamic-rangemedia queries detect screen capabilities.
Practice questions
Two buttons use hsl(60 90% 50%) and hsl(240 90% 50%) backgrounds with white text. Why is one hard to read, and how does oklch() help?
Answer
The yellow is much lighter than the blue, although both have 50% HSL lightness, so white text on yellow has very low contrast. In oklch(), colors with the same lightness look equally light, so giving both the same L, such as oklch(50% 0.1 100) and oklch(50% 0.1 265), keeps contrast similar.
Write a brand color in oklch(), then a lighter version and a more muted version of the same hue.
Answer
For example oklch(50% 0.14 145), oklch(85% 0.08 145) (higher lightness) and oklch(50% 0.04 145) (lower chroma). Keep the hue the same.
What does a user with an sRGB screen see for color: color(display-p3 1 0 0)?
Answer
The closest red the screen can show, which is close to sRGB red. Out-of-gamut colors are mapped when the browser paints them, so no fallback declaration is needed for that.
Why does this fallback not help in a browser without oklch()?
:root { --accent: #2f7d4f; --accent: oklch(52% 0.11 150); }
.link { color: var(--accent); }
Answer
Custom properties accept any value, so the second --accent declaration is valid and wins in every browser. It only fails when color: var(--accent) is computed, and then the declaration is invalid at computed-value time. Put the fallback in .link itself, or define the oklch token inside @supports (color: oklch(0 0 0)).
Previous: Color Basics: Names, Hex, rgb(), hsl(), hwb(), currentColor and Transparency
Next: Mixing and Deriving Colors: color-mix() and Relative Color Syntax

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.