Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Functions

The oklch() function

Reference for the CSS oklch() function: lightness, chroma and hue in the Oklab space, building even palettes, wide-gamut colors, alpha and examples.

The oklch() function is the polar form of Oklab: lightness, chroma (colorfulness) and a hue angle. It is the most practical notation for building palettes. Lightness behaves like human perception, so two colors with the same L look about equally light, and changing only the hue keeps their weight similar. That is hard to achieve with hsl().

CSS
:root {
  --brand: oklch(62% 0.19 255);
  --brand-dark: oklch(40% 0.15 255);
}

Try it

Even lightness across hues

The top row uses the same lightness and chroma with five hues, so the swatches look balanced. The bottom row is a ramp of one hue.

Syntax

CSS
oklch(L C H)
oklch(L C H / A)
oklch(from <color> L C H / A)

Syntax and arguments

Argument Description
L Lightness: a number 0โ€“1 or a percentage 0%โ€“100%.
C Chroma, from 0 (gray) to roughly 0.4. A number or a percentage where 100% equals 0.4.
H Hue, a number (degrees) or an angle; wraps at 360.
A Optional alpha, number 0โ€“1 or percentage.

Usage notes

  • Reasoning about palettes. To make a theme, vary L for shades and H for different colors, with C as the strength. Store the parts in custom properties and combine them.
  • Chroma has a ceiling. How much chroma is possible depends on lightness and hue. If you ask for more than the display can show, the browser maps the color into its gamut, so equal chroma numbers may not look equally vivid.
  • Wide gamut. On a wide-gamut screen, oklch() can reach colors that rgb() cannot. Offer a fallback (background: #3b82f6; first) if you support older browsers.
  • Gradients and mixing. linear-gradient(in oklch, ...) and color-mix(in oklch, ...) give lively results; mind the hue path for far-apart hues.
  • Contrast. Lightness differences correlate with contrast, but you must still test the actual pair.

Browser support

Supported in current versions of all major browsers; check a compatibility table for older ones.