lab()
Example
.brand {
color: lab(0.6 40 -20);
}.brand {
color: lab(60% 40 -20);
}In lab() lightness runs from 0 to 100, so a value under 1 is almost black.
Common mistakes
- Writing lightness as a value under 1, copied from
oklab(), which gives a near-black color. - Using commas between channels, which
lab()doesn't accept.
Key points
- Lightness is a percentage or a number from 0 to 100, not 0 to 1 as in
oklab(). - Hue changes use
lch()oroklch()instead of guessing 'a' and 'b' values. - Colors outside sRGB have a fallback declared before them.
Interview questions
What is the difference between lab() and oklab()?
Both use lightness plus 'a' and 'b' axes. Oklab fixes hue shifts that CIELAB has, especially in blues, so it is usually preferred for UI colors.
What is the difference between lab() and lch()?
They use the same color space. lab() uses 'a' and 'b' axes, while lch() expresses them as chroma and a hue angle.