CSS Reference Β· Functions
The oklab() function
Reference for the CSS oklab() function: the Oklab lightness, a and b axes, why it blends colors well, alpha, and live examples comparing gradients.
The oklab() function specifies a color in Oklab, a perceptual color space designed to be more uniform than CIE Lab. It has a lightness L and two axes: a (green to red) and b (blue to yellow). Its main strength is blending: gradients and mixes computed in Oklab avoid the muddy gray midpoints you often get in sRGB, and avoid the hue drift of older spaces.
.panel { background: oklab(0.7 0.1 -0.05); }
Try it
Both bars go from blue to yellow. The sRGB one passes through a dull gray in the middle; the Oklab one stays lighter and more even. The in oklab gradient syntax is relatively new, so the demo needs a recent browser.
Syntax
oklab(L a b) oklab(L a b / A) oklab(from <color> L a b / A)
Syntax and arguments
| Argument | Description |
|---|---|
L |
Lightness: a number from 0 to 1, or a percentage from 0% to 100%. |
a |
Greenβred axis. A number (roughly within Β±0.4) or a percentage, where 100% equals 0.4. |
b |
Blueβyellow axis, same scale. |
A |
Optional alpha, number 0β1 or percentage. |
Usage notes
- Note the scale. Unlike
lab(), lightness is0β1and the axes are small numbers like0.1. - Best for mixing.
color-mix(in oklab, ...)andlinear-gradient(in oklab, ...)give smooth, predictable results. - Editing by hand is awkward. Rotating hue means changing
aandbtogether;oklch()is the same space in polar form and usually easier for palettes. - Gamut. Values outside the displayable range are mapped by the browser.
- Not a text color shortcut. Equal lightness does not guarantee enough contrast; still check it.
Browser support
Supported in current versions of all major browsers. Check a compatibility table for older browsers, and give a fallback color first if needed.
Related
oklch()β polar formcolor-mix()β mixing in a chosen spacelab()- Lessons: Modern color, Gradients