Favorites

lab() CSS Function

lab()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The lab() function defines a color in the CIE Lab color space by lightness and two color axes, a (green to red) and b (blue to yellow).

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The lab() CSS function defines a color in the CIE Lab color space. Instead of mixing red, green and blue light, Lab describes a color with a lightness value and two color axes: a, which runs from green (negative) to red (positive), and b, which runs from blue (negative) to yellow (positive). Lab was designed to match human vision, so equal changes in its values look like roughly equal changes in color.

Lightness ranges from 0 (black) to 100 (white), or as a percentage. The a and b values are signed numbers that usually stay within about -125 to 125, where 100% equals 125. When both are 0, the result is a neutral gray. Lab covers every color humans can see, so it can express colors far outside the sRGB gamut; the browser maps these to the nearest color the display can show. An optional alpha value can follow a slash.

.warm {
  background-color: lab(65% 45 60);   /* orange */
}

.cool {
  background-color: lab(55% -30 -40); /* teal-blue */
}

.neutral {
  background-color: lab(70% 0 0);     /* mid gray */
}

/* Relative color: shift a color toward red */
.alert {
  color: lab(from var(--text) l calc(a + 20) b);
}

lab() is often used as an interpolation space in gradients and color-mix() because it avoids the dull, grayish midpoints that sRGB mixing can produce. Its polar form is lch(), and an improved version of the same idea is oklab().

Interactive Demo

Colour swatch
Demo Code
HTML Code
<div class="demo-checker">
	<div class="demo-element">Colour swatch</div>
</div>
CSS Code
.demo-checker {
	width: 296px;
	padding: 18px;
	box-sizing: border-box;
	background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0 / 20px 20px;
}
.demo-element {
	width: 260px;
	padding: 18px;
	border-radius: 8px;
	font-size: 16px;
	font-weight: bold;
	color: #fff;
	text-shadow: 0 1px 2px rgb(0 0 0 / 40%);
	background-color: lab(55 75 -5);
}

Syntax

lab() = lab( [ from <color> ]? [ <percentage> | <number> | none ]
[ <percentage> | <number> | none ]
[ <percentage> | <number> | none ]
[ / [ <alpha-value> | none ] ]? )

Values

  • L (lightness)A <number> from 0 to 100 or a <percentage> from 0% to 100%. 0 is black and 100 is white.
  • aA <number> or <percentage> for the green-red axis. Negative values are greener, positive values redder. 100% equals 125.
  • bA <number> or <percentage> for the blue-yellow axis. Negative values are bluer, positive values more yellow. 100% equals 125.
  • alphaOptional. An <alpha-value> after a slash (/) from 0 to 1, or a percentage.

Example

<div class="wrap">
<h1>CSS lab() examples</h1>
<div class="grid">
<div class="card">
<div class="sw red"></div>
<div class="label">lab(55% 70 50)</div>
</div>
<div class="card">
<div class="sw green"></div>
<div class="label">lab(60% -60 50)</div>
</div>
<div class="card">
<div class="sw blue"></div>
<div class="label">lab(45% 20 -70)</div>
</div>
<div class="card">
<div class="sw yellow"></div>
<div class="label">lab(85% 0 80)</div>
</div>
<div class="card">
<div class="sw gray"></div>
<div class="label">lab(65% 0 0)</div>
</div>
<div class="card">
<div class="sw gradient"></div>
<div class="label">linear-gradient(in lab, ...)</div>
</div>
</div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* lab() examples */
.sw {
height: 90px;
border-radius: 8px;
border: 1px solid rgba(16, 42, 67, 0.08);
}

.red { background: lab(55% 70 50); }
.green { background: lab(60% -60 50); }
.blue { background: lab(45% 20 -70); }
.yellow { background: lab(85% 0 80); }
.gray { background: lab(65% 0 0); }
.gradient { background: linear-gradient(in lab to right, lab(55% 70 50), lab(45% 20 -70)); }
Open in editor

Browser Support

The following information will show you the current browser support for the CSS lab() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.