CSS lab() Function

The CSS lab() function defines a color in the CIE L*a*b* (CIELAB) color space, which is designed to be perceptually uniform and represent the entire spectrum of human vision.

Introduced in CSS Color Module Level 4, the lab() function allows web developers to specify device-independent colors that can access wide-gamut displays (such as Display P3) beyond the standard sRGB color gamut.

Syntax

The lab() function accepts three space-separated values representing Lightness, the a-axis (green-to-red), and the b-axis (blue-to-yellow), plus an optional alpha transparency channel:

Parameters

Basic Examples

Here are several basic colors specified with the lab() function:

Using lab() in Style Sheets

The CSS specifications states that you can use lab() wherever a CSS <color> value is accepted. For example, you can use lab() to set the colors of text, backgrounds, and borders:

Specifying Transparency

An alpha channel can be added after a forward slash (/) to create semi-transparent colors:

How the a and b Axes Work

The CIELAB color space is based on the opponent-color theory of human vision, which suggests that our eyes perceive colors along two opposing axes:

Axis Negative Values (−) Zero (0) Positive Values (+)
a-axis Green Neutral Red / Magenta
b-axis Blue Neutral Yellow

When both a and b are set to 0, the color has no chroma and is a neutral shade of gray, determined entirely by the L (lightness) value.

Why Use lab()?

Related Color Functions