UI design

Building a colour palette with OKLCH in CSS

OKLCH lets you build colour palettes with evenly spaced shades and predictable contrast. Here is the syntax, an 11-step scale with real contrast results, and how to use it safely.

OKLCH is a way of writing colours in CSS as lightness, chroma and hue, where the lightness value matches how bright the colour actually looks. That makes it the easiest colour space for building a palette: keep the hue, step the lightness evenly, and every shade looks evenly spaced, with predictable contrast.

This guide explains the oklch() syntax, why it beats HSL for palettes, how to build an 11-step scale from 50 to 950, and how to use it today with safe fallbacks.

Key takeaways

  • oklch(L C H): lightness from 0 to 1, chroma (colourfulness) from 0 to about 0.37, hue from 0 to 360.
  • Equal lightness in OKLCH looks equally light across hues. In HSL it doesn’t.
  • Build a scale by fixing the hue, stepping lightness, and easing chroma off at the light and dark ends.
  • oklch() has worked in all major browsers since May 2023.
  • Lightness helps, but always check text pairs against WCAG contrast.

What OKLCH is

OKLCH is the cylindrical form of the Oklab colour space, designed so that numeric changes match perceived changes. In CSS it takes three values and an optional alpha:

.button {
  /* lightness  chroma  hue  / alpha */
  background: oklch(0.6 0.19 262);
  color: oklch(0.97 0.014 262);
  border-color: oklch(0.6 0.19 262 / 0.5);
}
  • L (lightness): 0 is black, 1 is white. You can also write it as a percentage.
  • C (chroma): 0 is grey. Higher values are more colourful. The maximum depends on the hue and the display.
  • H (hue): an angle around the colour wheel, roughly red at 30, yellow at 100, green at 145 and blue at 260.

Why OKLCH beats HSL for palettes

HSL’s lightness is a mathematical value, not a perceived one. Yellow and blue at the same HSL lightness look completely different, which you can see in their contrast against white:

ColourHexContrast on white
hsl(60 100% 50%) yellow#ffff001.07:1
hsl(120 100% 50%) green#00ff001.37:1
hsl(240 100% 50%) blue#0000ff8.59:1
oklch(0.7 0.15 100) yellow#b59f002.65:1
oklch(0.7 0.15 145) green#5bb6612.53:1
oklch(0.7 0.15 260) blue#659dfb2.70:1

The three HSL colours share a lightness of 50% but range from almost invisible to strong contrast. The three OKLCH colours share a lightness of 0.7 and land within a narrow band. That consistency is what makes OKLCH palettes predictable: change the hue and your 500 shade still behaves like a 500 shade.

Building an 11-step palette

Tailwind-style scales run from 50 (lightest) to 950 (darkest). In OKLCH the recipe is simple: fix the hue, space the lightness values, and lower the chroma towards both ends, where very light and very dark colours can’t hold much colour anyway.

:root {
  --blue-50: oklch(0.97 0.014 262);
  --blue-100: oklch(0.94 0.03 262);
  --blue-200: oklch(0.88 0.06 262);
  --blue-300: oklch(0.8 0.1 262);
  --blue-400: oklch(0.7 0.15 262);
  --blue-500: oklch(0.6 0.19 262);
  --blue-600: oklch(0.52 0.2 262);
  --blue-700: oklch(0.45 0.18 262);
  --blue-800: oklch(0.38 0.15 262);
  --blue-900: oklch(0.3 0.11 262);
  --blue-950: oklch(0.22 0.08 262);
}

Here is how those shades perform with white and black text, measured with the WCAG formula:

StepsRGB hexWhite textBlack text
50#f0f5ff1.09:119.21:1
200#c2d8ff1.44:114.56:1
400#6a9cfb2.71:17.76:1
500#3c79f04.05:15.19:1
600#1f5ed95.74:13.66:1
700#144bb77.72:12.72:1
900#0b296413.86:11.52:1

In this scale, 600 and darker pass AA for normal white text (4.5:1), while 500 and lighter need dark text. Knowing where that switch happens is useful for buttons and badges, and it stays in roughly the same place when you build a second palette in another hue.

Gamut: when chroma is too high

OKLCH can describe colours that a standard sRGB screen can’t show. Many recent phones and laptops have wider Display P3 screens that can show more saturated colours. If you ask for more chroma than the screen supports, the browser maps the colour to the nearest one it can display.

  • Mid-lightness steps can hold the most chroma. Very light and very dark steps can’t, which is why the scale above eases chroma off at both ends.
  • If you want vivid colours only on wide-gamut screens, wrap them in @media (color-gamut: p3) { … }.
  • Check the hex output: if two neighbouring steps convert to the same sRGB colour, you’ve pushed chroma beyond what sRGB can show.

Hover states and tints without new variables

Two newer CSS features pair well with OKLCH. color-mix() blends colours in a chosen space, and relative colour syntax adjusts one channel of an existing colour:

.button {
  background: var(--blue-600);
}
.button:hover {
  /* 0.06 darker, same chroma and hue */
  background: oklch(from var(--blue-600) calc(l - 0.06) c h);
}
.badge {
  /* 15% of the brand colour mixed into white */
  background: color-mix(in oklch, var(--blue-600) 15%, white);
}

color-mix() has worked across major browsers since 2023. Relative colour syntax has worked in all of them since 2024 (Chrome 119, Firefox 128 and Safari 18), so add a plain fallback if you support older versions.

Tip: Put a hex fallback before each OKLCH value, such as background: #1f5ed9; background: oklch(0.52 0.2 262);. Browsers that don’t understand the second line keep the first.

OKLCH in practice

You don’t need to move a whole codebase at once. Start with new design tokens, or rebuild one brand palette in OKLCH and compare it with the old one. Tailwind CSS v4 already defines its default palette in OKLCH, so if you use it you’re working with these values already.

OKLCH lightness is a good guide to contrast but not a replacement for checking it. WCAG measures contrast with its own formula, so test real text and background pairs; the WCAG contrast ratio guide explains the rules.

Generate a palette from one colour

The palette generator in Refract’s contrast checker does all of this for you. Pick a brand colour and it builds an OKLCH scale from 50 to 950, shows whether white or black text passes on each swatch, adds complementary or analogous harmonies if you want them, and exports CSS variables, Tailwind config or JSON. To try a palette as a background, take any two steps into the CSS gradient generator.

Source: MDN: oklch().