oklch()
Writes a colour through lightness, chroma, and hue in a space matched to the eye. Colours of the same lightness look equally light.
Example
#:root {
--primary: oklch(62% 0.22 295);
--success: oklch(62% 0.15 155);
--danger: oklch(62% 0.21 25);
}
.btn { color: #fff; }
.btn.primary { background: var(--primary); }
.btn.success { background: var(--success); }
.btn.danger { background: var(--danger); }<style>
.btn { padding: 10px 16px; border: 0; border-radius: 10px; font: 600 15px system-ui, sans-serif; }
</style>
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<button class="btn primary" type="button">Next</button>
<button class="btn success" type="button">Passed</button>
<button class="btn danger" type="button">Delete</button>
</div>All three colours have the same lightness L = 62%, so white text has similar contrast on each of them.
Definition and usage
#The oklch() function describes a colour with three numbers. L is lightness from 0% to 100% (or from 0 to 1), C is chroma, the intensity of the colour, from 0 upwards, in practice up to about 0.37, and H is the hue in degrees on the colour wheel. It works similarly to hsl(), but the colour space is built around how the human eye perceives lightness.
The biggest advantage: the same L value really does look equally light in every hue. oklch(70% 0.12 90) (yellow) and oklch(70% 0.12 260) (blue) look similarly light to the eye, whereas in HSL at equal lightness the yellow would be clearly lighter. This makes it easier to build palettes and predict text contrast against the background.
OKLCH also covers colours outside the sRGB range. Newer screens, for example with a P3 gamut in phones and laptops, show more saturated colours than you can describe in rgb() or hex. If you give a chroma the screen can’t display, the browser picks the nearest possible colour itself.
You add transparency after a slash: oklch(65% 0.17 300 / 0.5). Hues are distributed differently than in HSL: red falls around 29, green around 142, and blue around 264 degrees.
Syntax
#oklch(<lightness> <chroma> <hue> [/ <alpha>]?)Colour variants
#base colour
A purple of medium lightness and a clear but not excessive chroma.lightness 45%
Lower L with the same chroma and hue. The colour gets darker but stays the same purple.chroma 0.07
Low chroma gives a muted, subdued purple. With C equal to 0 you would get pure grey of the same lightness.hue 150
A different hue at the same lightness. The green looks as light as the purple from the first example, because L hasn’t changed.alpha 0.4
Transparency after a slash, just like inrgb()andhsl().
Colour variants in practice
#oklch(65% 0.17 300)
.demo { background: oklch(65% 0.17 300); }oklch(45% 0.17 300)
.demo { background: oklch(45% 0.17 300); }oklch(65% 0.07 300)
.demo { background: oklch(65% 0.07 300); }oklch(65% 0.17 150)
.demo { background: oklch(65% 0.17 150); }oklch(65% 0.17 300 / 0.4)
rgb() and hsl()..demo { background: oklch(65% 0.17 300 / 0.4); }More examples
#.hsl span {
background: hsl(var(--h) 90% 50%);
}
.oklch span {
background: oklch(70% 0.12 var(--h));
}<style>
.row { display: flex; gap: 6px; margin-bottom: 10px; }
.row span { flex: 1; height: 44px; border-radius: 8px; }
.label { margin: 0 0 4px; color: #a1a1aa; font-size: 13px; }
</style>
<p class="label">hsl(h 90% 50%): lightness equal only in numbers</p>
<div class="row hsl"><span style="--h: 30"></span><span style="--h: 90"></span><span style="--h: 150"></span><span style="--h: 260"></span></div>
<p class="label">oklch(70% 0.12 h): lightness equal to the eye</p>
<div class="row oklch"><span style="--h: 30"></span><span style="--h: 90"></span><span style="--h: 150"></span><span style="--h: 260"></span></div>In the top row the yellow-green glows clearly stronger than the blue, even though all the colours have L = 50%. In the bottom row they look similarly light.
Browser support
#Widely available · since 2023
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Build palettes by changing only L while keeping C and H constant. Successive shades will be evenly lighter and won’t shift in hue.
- Keep chroma moderate, for example from 0.1 to 0.2. Very high values go beyond what many screens can show and will be clipped.
- Create new colours from existing ones with
color-mix(in oklch, …). Mixing in this space gives nicer intermediate colours than in sRGB.
Related entries
#- hsl()Writes a colour through its hue on the colour wheel, saturation, and lightness. It makes it easy to lighten, darken, or mute a colour.
- rgb()Writes a colour as a mix of red, green, and blue light, with optional transparency. It also covers hex notation.
- color-mix()Mixes two colours in given proportions and in a chosen colour space. It creates lighter, darker, and semi-transparent variants.
- colorSets the text colour and the default colour of borders, decorations and SVG icons that use currentcolor.
- linear-gradient()Creates a smooth colour transition along a straight line. It is used as an image, most often in background or background-image.
Spotted a mistake or missing an example? Write to us.