Skip to content
Quillyst
All posts

Accessible color palettes with OKLCH

Perceptually uniform color makes contrast predictable. Here is how to build a palette that passes WCAG by design.

Leo Martinez1 min read

If you have ever built a palette in HSL, you know the problem: hsl(60 100% 50%) and hsl(240 100% 50%) share the same “lightness” value, yet yellow looks far brighter than blue. Contrast becomes guesswork. OKLCH fixes that.

What OKLCH gives you

OKLCH describes a color with three channels:

  • L — perceived lightness, from 0 to 1.
  • C — chroma, or how colorful it is.
  • H — hue angle, from 0 to 360.

Because lightness is perceptual, two colors with the same L look equally bright to the human eye, whatever their hue.

:root {
  --blue-600: oklch(0.55 0.2 260);
  --green-600: oklch(0.55 0.2 145);
  --pink-600: oklch(0.55 0.2 350);
}

All three of these sit at roughly the same contrast against white.

Building a scale

Pick lightness stops once, then reuse them for every hue. A scale of 0.97, 0.93, 0.85, 0.75, 0.65, 0.55, 0.45, 0.35, 0.25 gives predictable steps for backgrounds, borders and text.

Rules that keep you compliant

  1. Body text sits at least 0.45 apart in lightness from its background.
  2. Large text and icons can go down to about 0.35 apart.
  3. Verify with a real contrast checker — perceptual is close, not exact.

Dark mode for free

Invert the lightness stops and keep hue and chroma. Because the scale is perceptual, the dark palette keeps the same relationships without hand-tuning every swatch.

Related

Keep reading

View all posts

Type to search across all articles.