Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

oklab(): perceptual color with a D65 white point

Use Oklab lightness and opponent axes without confusing its numeric scale with CIE Lab.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

color: oklab(50% 0.1 0 / 0.5);

oklab() expresses a color with lightness L and opponent axes a and b. Oklab uses a D65 white point and was designed for useful perceptual behavior in color operations. Positive a moves toward red and negative a toward green; positive b moves toward yellow and negative b toward blue. Neutral colors have both axes at zero.

For lightness, 50% corresponds to the number 0.5, not 50. This differs from the numeric lightness scale used by lab(). The two spaces are not interchangeable just because their coordinate names look similar. Modern syntax uses spaces and optional slash alpha. Conversion to the output color space and gamut handling can affect the displayed result, particularly for highly chromatic colors.

The example rasterizes oklab(50% 0 0) and oklab(0.5 0 0), obtaining the same gray around RGB 99,99,99. It contrasts this with neutral lab(50% 0 0), which yields about 119,119,119 in the same renderer. A positive-a Oklab sample demonstrates the chromatic axis. These comparisons show why copying numbers between the two models changes the color.

Examples

const sample=async style=>{const svg='<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8"><rect width="8" height="8" fill="white"/><foreignObject width="8" height="8"><div xmlns="http://www.w3.org/1999/xhtml" style="width:8px;height:8px;'+style.replaceAll('&','&amp;').replaceAll('"','&quot;')+'"></div></foreignObject></svg>';const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=canvas.height=8;const context=canvas.getContext('2d');context.drawImage(image,0,0);return [...context.getImageData(4,4,1,1).data].slice(0,3).join(',')};
const neutral=await sample('background:oklab(50% 0 0)');
const sameNumber=await sample('background:oklab(0.5 0 0)');
const cie=await sample('background:lab(50% 0 0)');
const opponent=await sample('background:oklab(50% 0.1 0)');
console.log('neutral='+neutral+'; numeric-L='+sameNumber+'; CIE-Lab='+cie+'; positive-a='+opponent);

Result

neutral=99,99,99; numeric-L=99,99,99; CIE-Lab=119,119,119; positive-a=144,73,97

The percent and decimal Oklab forms match; the CIE Lab comparison deliberately does not.

Sources