Sub topic 2
Perceptual uniformity: what Oklab and OKLCH fix
This chapter assumes you know CSS custom properties and the hex, rgb() and hsl() notations. It explains why those notations make colors hard to adjust predictably, and what the Oklab and OKLCH models change.
The problem with "same lightness" in HSL
In hsl(), the third number is called lightness. You might expect that two colors with the same lightness look equally bright. They don't.
.hsl-yellow {
background: hsl(60 100% 50%);
}
.hsl-blue {
background: hsl(240 100% 50%);
}Both colors have 50% lightness. Pure yellow looks very bright, and pure blue looks dark. HSL is a rearrangement of RGB values. It describes how much of each screen channel is turned on. It does not describe how bright a color looks to a person.
This causes problems in practice:
- A palette built by changing only the hue gives swatches of uneven brightness.
- Text on a yellow background and text on a blue background with the same HSL lightness have very different contrast.
- Lowering lightness by 10 points darkens some hues much more visibly than others.
- Gradients between saturated colors can pass through muddy or oddly shifted tones.
Perceptual uniformity
A color model is perceptually uniform when equal numeric changes look like equal visual changes. If you move lightness from 60 to 70 and from 80 to 90, the two steps should look about the same size. This holds for any hue.
No model is perfectly uniform, because human vision is complicated. Some models are much closer than HSL, though.
Oklab and OKLCH
Oklab is a color space published in 2020 by Björn Ottosson. It is built from data about how people see color, and it is designed so that distances between colors roughly match perceived differences. Its three axes are:
L: perceived lightness, from black to white.a: position on a green to red axis.b: position on a blue to yellow axis.
Two axes at right angles are hard to reason about when you want to say "same color, but more vivid" or "same color, but rotated toward green". OKLCH is the same space written in polar form. It replaces a and b with an angle and a distance from the gray center:
L: lightness, the same as in Oklab.C: chroma, how far the color is from gray. Higher means more vivid.H: hue, the angle around the center, in degrees.
flowchart LR
A[sRGB values] --> B[Oklab: L, a, b]
B --> C[OKLCH: L, C, H]To see the diagram, use the block below.
OKLCH keeps Oklab's uniform lightness. It gives you the three controls designers usually want, as separate numbers.
The same test in OKLCH
Here is the yellow and blue comparison again, with the lightness held at 75% in OKLCH.
.oklch-yellow {
background: oklch(75% 0.15 100);
}
.oklch-blue {
background: oklch(75% 0.15 255);
}These two colors look about equally bright. Because lightness means the same thing for every hue, you can change the hue and keep the apparent brightness steady. You can also darken any color by lowering L, as in this hover rule:
.button {
background: oklch(60% 0.15 250);
}
.button:hover {
background: oklch(52% 0.15 250);
}Only lightness changes. Chroma and hue stay fixed, so the hover state reads as the same color, just darker.
What changes compared with HSL
| Question | `hsl()` | `oklch()` |
|---|---|---|
| Does equal lightness look equally bright across hues? | No | Mostly yes |
| Is a fixed lightness step an even visual step? | Varies by hue | Close to even |
| Do blues stay blue when lightened or mixed? | Often drift toward purple | Much more stable |
| Is the full lightness range available for every hue? | Yes, by definition | No, see below |
The last row matters. In OKLCH, some combinations of lightness, chroma and hue describe colors a display cannot show. A very vivid yellow at low lightness, for example, doesn't exist on a normal screen. The browser has to adjust such values, and a later chapter covers gamut limits and fallbacks.
Common mistakes
- Treating the numbers like HSL. Chroma is not a percentage of saturation. Typical on-screen values run from
0to roughly0.4, and the useful range depends on lightness and hue. - Using the same chroma for every hue. Each hue reaches a different maximum chroma, so a fixed value may be out of range for some of them.
- Assuming uniform means accessible. Equal lightness gives equal brightness, but it doesn't guarantee that text on a background has enough contrast. You still need to check contrast, which a later chapter covers.
Exercise
You build a button palette in HSL with hsl(60 100% 50%) for yellow and hsl(240 100% 50%) for blue. Both buttons look unbalanced. Why does this happen, and what would you change to get buttons of similar brightness?
Show answer
HSL lightness is derived from RGB channel values, not from how bright a color looks, so pure yellow looks much brighter than pure blue at the same 50%. Switching to OKLCH and giving both colors the same L, for example oklch(75% 0.15 100) and oklch(75% 0.15 255), gives buttons of similar perceived brightness. You may also need to reduce chroma if a color falls outside the display gamut.