Skip to content
Tutorials Center
My learning

Topics

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.

CSS
.panel {
  background: oklab(0.7 0.1 -0.05);
}

Try it

Gradient in sRGB vs Oklab

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

CSS
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 is 0–1 and the axes are small numbers like 0.1.
  • Best for mixing. color-mix(in oklab, ...) and linear-gradient(in oklab, ...) give smooth, predictable results.
  • Editing by hand is awkward. Rotating hue means changing a and b together; 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.