Favorites

oklab() CSS Function

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

The oklab() function defines a color by lightness and two color axes in the Oklab color space, which is good for smooth gradients and mixing.

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 oklab() CSS function defines a color in the Oklab color space using a lightness value and two color axes, a (green to red) and b (blue to yellow). Oklab was created as an improved version of CIE lab(): it predicts perceived lightness, chroma and hue more accurately, especially for saturated blues, while remaining simple to calculate.

Lightness is a number from 0 (black) to 1 (white), or a percentage. The a and b axes are signed numbers that usually stay between about -0.4 and 0.4, where 100% equals 0.4. Setting both to 0 gives a neutral gray. Colors outside the screen's gamut are mapped to the nearest displayable color, and an optional alpha value can follow a slash.

.surface {
  background-color: oklab(97% 0 0);        /* near-white neutral */
}

.danger {
  background-color: oklab(60% 0.18 0.09);  /* red */
}

.info {
  background-color: oklab(60% -0.05 -0.15); /* blue */
}

/* Smooth gradient with no muddy midpoint */
.hero {
  background: linear-gradient(in oklab to right, #ff0080, #00c3ff);
}

Oklab is the default interpolation space for many modern CSS features, such as gradients written with in oklab and color-mix(), because mixing in it produces even, natural-looking transitions. Its polar form, oklch(), is usually easier to write by hand.

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: oklab(0.65 0.23 0);
}

Syntax

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

Values

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

Example

<div class="wrap">
<h1>CSS oklab() examples</h1>
<div class="grid">
<div class="card">
<div class="sw red"></div>
<div class="label">oklab(60% 0.18 0.09)</div>
</div>
<div class="card">
<div class="sw green"></div>
<div class="label">oklab(65% -0.15 0.12)</div>
</div>
<div class="card">
<div class="sw blue"></div>
<div class="label">oklab(55% -0.04 -0.18)</div>
</div>
<div class="card">
<div class="sw gray"></div>
<div class="label">oklab(70% 0 0)</div>
</div>
<div class="card">
<div class="sw mix-srgb"></div>
<div class="label">gradient in srgb</div>
</div>
<div class="card">
<div class="sw mix-oklab"></div>
<div class="label">gradient in oklab</div>
</div>
</div>
<p class="note">Compare the two gradients: the oklab one keeps a brighter, cleaner midpoint.</p>
</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;
}

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

.red { background: oklab(60% 0.18 0.09); }
.green { background: oklab(65% -0.15 0.12); }
.blue { background: oklab(55% -0.04 -0.18); }
.gray { background: oklab(70% 0 0); }
.mix-srgb { background: linear-gradient(in srgb to right, #ff0080, #00c3ff); }
.mix-oklab { background: linear-gradient(in oklab to right, #ff0080, #00c3ff); }
Open in editor

Browser Support

The following information will show you the current browser support for the CSS oklab() 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.