CSS Reference Β· Functions
The lab() function
Reference for the CSS lab() function: CIE Lab lightness and the a and b axes, wide-gamut colors, alpha, how it differs from oklab(), and live examples.
The lab() function specifies a color in the CIE Lab color space. It has a lightness axis L and two color axes: a runs from green (negative) to red (positive), and b runs from blue (negative) to yellow (positive). Lab is designed so that equal numeric changes look roughly equally different to a human eye, and it can describe every color a person can see, including colors outside the sRGB gamut.
.accent { background: lab(55% 60 40); }
Try it
The first row moves along the gray axis, the second shifts green to red, the third blue to yellow.
Syntax
lab(L a b) lab(L a b / A) lab(from <color> L a b / A)
The result is a <color>. Colors that your display cannot show are mapped to the closest displayable color when painted.
Syntax and arguments
| Argument | Description |
|---|---|
L |
Lightness: a number from 0 to 100, or a percentage from 0% to 100%. |
a |
Greenβred axis. A number (typically within about Β±125) or a percentage, where 100% equals 125. |
b |
Blueβyellow axis, same scale as a. |
A |
Optional alpha, number 0β1 or percentage. |
Usage notes
- No "unit" for a and b. Plain numbers; there is no angle or percent sign needed.
- Gamut mapping. A very vivid
lab()value may be outside what the screen can show; the browser clips or maps it, so very different numbers can look identical on a standard display. - Prefer the polar form for palettes. Changing hue by editing
aandbtogether is awkward;lch()exposes chroma and hue directly. - Blue shift in gradients. Lab has a known quirk where blues can drift toward purple when you change lightness;
oklab()was designed to behave better. - Interpolation. Gradients and
color-mix()can interpolatein labfor smoother, more even blends than sRGB.
Browser support
Supported in current versions of all major browsers. Check a compatibility table before relying on it for older ones, and provide a fallback color above it if needed.
Related
lch()β polar form of Laboklab()β improved perceptual spacecolor-mix()- Lesson: Modern color