lab()
The lab() functional notation expresses a given color in the CIE L*a*b* color space. Lab represents the entire range of color that humans can see.
Syntax
css
lab(29.2345% 39.3825 20.0664);
lab(52.2345% 40.1645 59.9971);
lab(52.2345% 40.1645 59.9971 / .5);
Values
Functional notation: lab(L a b[ / A])
L-
A
<number>between0and100or a<percentage>between0%and100%that specifies the CIE Lightness where the number0corresponds to0%(black) and the number100corresponds to100%(white). a-
A
<number>between-125and125or a<percentage>between-100%and100%, specifying the distance along theaaxis in the Lab colorspace, that is how green/red the color is. b-
A
<number>between-125and125or a<percentage>between-100%and100%, specifying the distance along thebaxis in the Lab colorspace, that is how blue/yellow the color is. AOptional-
An
<alpha-value>, where the number1corresponds to100%(full opacity).
Note: Usually when percentage values have a numeric equivalent in CSS, 100% is equal to the number 1.
This case is notable where 100% is equal to the number 100 for the L value and 125 for the a and b values.
Formal syntax
Examples
Adjusting lightness and color axes with lab()
The following example shows the effect of varying the lightness, a-axis, and b-axis values of the lab() function.
HTML
html
<div data-color="red"></div>
<div data-color="red-a"></div>
<div data-color="green"></div>
<div data-color="green-b"></div>
<div data-color="blue"></div>
<div data-color="blue-light"></div>
CSS
css
[data-color="red"] {
background-color: lab(100 125 125);
}
[data-color="red-a"] {
background-color: lab(100 110 125);
}
[data-color="green"] {
background-color: lab(75% -120 125);
}
[data-color="green-b"] {
background-color: lab(75% -120 10);
}
[data-color="blue"] {
background-color: lab(0 -120 -120);
}
[data-color="blue-light"] {
background-color: lab(70 -120 -120);
}
Result
Adjusting opacity with lab()
The following example shows the effect of varying the A (alpha) value of the lab() functional notation.
The red and red-alpha elements overlap the #background-div element to demonstrate the effect of opacity.
Giving A a value of 0.4 makes the color 40% opaque.
HTML
html
<div id="background-div">
<div data-color="red"></div>
<div data-color="red-alpha"></div>
</div>
CSS
css
[data-color="red"] {
background-color: lab(100 125 125);
}
[data-color="red-alpha"] {
background-color: lab(100 125 125 / 0.4);
}
Result
Specifications
| Specification |
|---|
| CSS Color Module Level 4 # lab-colors |
Browser compatibility
BCD tables only load in the browser
See also
- The
<color>data type for a list of all color notations - LCH colors in CSS: what, why, and how?
- Safari Technology Preview 122 release notes: includes
lab()andlch()colors