Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

oklab() is a CSS color function that specifies a color using the Oklab color space. It takes lightness and two color-axis values, with an optional alpha value for transparency. The values describe a color mathematically; a browser still has to map it to the capabilities of the display.

What `oklab()` means

Oklab is a Lab-like color space: its channels are L for lightness and a and b for color axes. Unlike RGB coordinates, which describe red, green, and blue components, Oklab is designed to make lightness and color relationships more perceptually regular.

The W3C describes Oklab as improving hue linearity, hue uniformity, and chroma uniformity compared with CIE LCH. That is a design goal, not a guarantee that every numerical change will look equally large to every observer in every viewing condition. W3C CSS Color Module Level 4

How to write an `oklab()` color

The function accepts three channels in order—lightness, a, and b—and optionally an alpha value after a slash. Each channel can be a number, a percentage, or none. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
/* lightness, a axis, b axis */
color: oklab(0.65 0.02 0.12);

/* lightness as a percentage, with 80% opacity */
color: oklab(65% 0.02 0.12 / 80%);

The percentage notation is not a single shared scale for all three channels. The W3C syntax and channel reference ranges are documented in the CSS Color Module Level 4 specification.

What the three channels do

  • L (lightness): ranges from 0 to 1, where 0 is black and 1 is diffuse white. Its percentage equivalent is 0% to 100%. Values outside the range are clamped to the range at parse time.
  • a: a signed color-axis coordinate. Its percentage reference range is -100% to 100%, equivalent to -0.4 to 0.4.
  • b: the other signed color-axis coordinate, using the same percentage reference range as a: -100% to 100%, equivalent to -0.4 to 0.4.

The a and b values work together to locate the color on two axes; they are not red and blue channels. Their signs and magnitudes affect the color’s hue and chroma.

Rank #2
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

How alpha works

Put alpha after a slash to specify opacity. For instance, oklab(65% 0.02 0.12 / 80%) requests 80% opacity. Alpha is optional, so a function without the slash specifies an opaque color.

Choosing between Oklab, RGB, and OkLCh

There is no universally best notation. Choose the form that makes the values and operation you care about easiest to understand.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Notation What it expresses Useful when
RGB Red, green, and blue color coordinates. You need to work directly with RGB values or an existing RGB-based palette.
oklab() Lightness plus Cartesian a and b color axes. You want to adjust lightness or work with color coordinates in Oklab.
OkLCh The polar form of Oklab, with chroma and hue expressed explicitly. You want to reason directly about hue and chroma rather than Cartesian axes.

Oklab and OkLCh are two ways to represent colors in related forms; one may be clearer than the other for a particular palette or interpolation task. The choice does not remove the need to consider the target display’s gamut.

Why the displayed color may differ

A CSS color value is not a promise that every screen will emit an identical appearance. The function can specify colors outside the gamut of a target display. The browser maps the requested color to the display’s capabilities, and an out-of-gamut color may be altered through gamut mapping. Oklab’s perceptual design does not override the display’s limits. See the W3C’s CSS Color Module Level 4 for the color-space and gamut-mapping context.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Browser support

MDN describes oklab() as well established and supported across many devices and browser versions, but that broad statement does not establish a particular minimum version for every browser or embedded webview. Check a current compatibility table and test the actual browsers and webviews your project supports. MDN: oklab()

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.