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().
:root { --brand: oklch(62% 0.19 255); --brand-dark: oklch(40% 0.15 255); }
Try it
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
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
Lfor shades andHfor different colors, withCas 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 thatrgb()cannot. Offer a fallback (background: #3b82f6;first) if you support older browsers. - Gradients and mixing.
linear-gradient(in oklch, ...)andcolor-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.
Related
oklab()โ rectangular formcolor-mix()hsl()- Lesson: Modern color