Modern Color with oklch(): Perceptually Uniform Palettes and Accessible Contrast

Build oklch CSS palettes that stay perceptually uniform: lightness, chroma and hue, relative colors, color-mix(), wide gamut and WCAG checks.

Executive Summary: oklch() describes a color by perceived lightness, chroma (colorfulness) and hue. Unlike HSL, equal lightness values look equally light across hues, so a palette built by stepping lightness behaves predictably: every 600 shade carries similar visual weight and similar contrast against white. Combined with relative color syntax and color-mix(), it lets you derive hover states, tints and dark mode variants in CSS instead of hand-picking hex codes. Lightness predicts contrast far better than HSL does, but WCAG ratios still need to be checked with a tool.
Row of color swatches generated with oklch lightness, chroma and hue

Build a palette in HSL and you will hit this within an hour. Set yellow and blue to the same hsl() lightness of 50% and full saturation. The blue is a deep, dark color that reads well on white, at about 8.6:1 contrast. The yellow is so bright it is nearly invisible on white, at about 1.07:1. Same “lightness” number, completely different perceived lightness. Every HSL-based design system ends up hand-tuning each hue to compensate.

oklch() is a CSS color function based on the OKLCH color space, a cylindrical form of Oklab, which Björn Ottosson published in 2020 to model how people perceive color. Its three channels are L, perceived lightness from 0% (black) to 100% (white); C, chroma, from 0 (gray) to roughly 0.37 for the most vivid colors; and H, hue angle from 0 to 360 degrees. It has worked in every major browser since 2023, along with color-mix(). Relative color syntax followed in 2024.

My position: new design systems should define their palettes in oklch(). It is not just a different notation. It turns palette generation from taste-driven tweaking into a mostly mechanical process, which means consistency survives the next designer and the next brand color.

Why perceptual uniformity matters

A color space is perceptually uniform when equal numeric changes produce roughly equal visible changes. HSL is not: it is a simple reshaping of RGB, and its lightness ignores the fact that human eyes are far more sensitive to green and yellow light than to blue. OKLCH’s lightness tracks perception closely, so:

  • Colors with the same L look about equally light, whatever their hue.
  • Changing hue at fixed L and C rotates the color without making it look lighter or darker.
  • Stepping L in equal amounts produces evenly spaced shades.
/* HSL: same numbers, wildly different perceived lightness */
.warning { background: hsl(60 100% 50%); }   /* blinding yellow */
.info    { background: hsl(240 100% 50%); }  /* deep blue */

/* OKLCH: same L and C, similar visual weight */
.warning { background: oklch(70% 0.15 90); }   /* muted amber */
.info    { background: oklch(70% 0.15 260); }  /* mid blue */

Building a palette by stepping lightness

The method is simple: pick a hue, step lightness from near-white to near-black, and shape chroma so it peaks in the middle and tapers at the ends. Very light and very dark colors cannot hold much chroma, and pushing it too high produces colors outside the display’s gamut.

:root {
  --blue-50:  oklch(97% 0.02 255);
  --blue-100: oklch(93% 0.04 255);
  --blue-200: oklch(86% 0.08 255);
  --blue-300: oklch(77% 0.12 255);
  --blue-400: oklch(68% 0.16 255);
  --blue-500: oklch(60% 0.19 255);
  --blue-600: oklch(52% 0.19 255);
  --blue-700: oklch(45% 0.17 255);
  --blue-800: oklch(37% 0.13 255);
  --blue-900: oklch(29% 0.09 255);
}

To create a green or red scale, copy the lightness column and change the hue. Adjust chroma per hue where needed, because the maximum chroma a display can show differs by hue: yellows and greens can hold much more chroma at high lightness than blues can. The important part is that the L column stays the same across every scale. That gives you a property HSL palettes never had: --green-600, --red-600 and --blue-600 carry similar visual weight, so status colors look balanced next to each other.

These primitives slot straight into the three-tier token system from the custom properties guide, with semantic tokens such as --color-accent pointing at them.

Lightness and contrast

WCAG 2.2 contrast ratios are computed from relative luminance, not from OKLCH lightness, so L is not a contrast formula. It is, however, a far better predictor than HSL lightness, which makes it useful for planning. Two approximate anchors help:

  • A neutral gray around L 57% has close to 4.5:1 contrast with white, and also with black. That middle band is the danger zone where neither black nor white text has much margin.
  • Shades at L 52% and below generally give white text 4.5:1 or better for body text, and shades at L 70% and above generally give black or near-black text the same, with chromatic colors varying a little by hue.

In the palette above, that means steps 600 to 900 are for text or for backgrounds under white text, steps 50 to 300 are for backgrounds under dark text, and 400 to 500 need checking case by case. Treat these as design rules, then verify the actual pairs with a contrast checker. The WCAG 2.2 thresholds remain 4.5:1 for normal text, 3:1 for large text and 3:1 for meaningful non-text elements such as input borders and focus indicators.

You may see APCA, the Advanced Perceptual Contrast Algorithm, discussed for a future WCAG 3. It models perception better, but it is not part of any current legal standard. Design with WCAG 2.2 ratios for compliance.

Deriving colors with relative color syntax

Relative color syntax lets you take an existing color, read its channels, and change some of them. In oklch(from ...), the keywords l, c and h stand for the source color’s channels, with l as a number from 0 to 1.

.button {
  --bg: var(--color-accent);
  background: var(--bg);
}

.button:hover {
  background: oklch(from var(--bg) calc(l - 0.06) c h);      /* slightly darker */
}

.button:active {
  background: oklch(from var(--bg) calc(l - 0.12) c h);      /* darker still */
}

.button:disabled {
  background: oklch(from var(--bg) l calc(c * 0.3) h);       /* desaturated */
}

.badge {
  background: oklch(from var(--color-accent) l c h / 0.15);  /* translucent tint */
}

Because L is perceptual, “subtract 0.06 lightness” produces a hover state that looks equally darker for every button color, including ones you have not chosen yet. One rule now covers every variant, and a rebrand needs no new hover colors.

Mixing colors with color-mix()

color-mix() blends two colors in a color space you choose. It is ideal for tints and shades of a base color.

.alert {
  background: color-mix(in oklab, var(--color-danger), white 88%);    /* pale tint */
  border-color: color-mix(in oklab, var(--color-danger), white 50%);
  color: color-mix(in oklab, var(--color-danger), black 30%);         /* deeper shade */
}

The interpolation space matters. Mixing in srgb tends to produce muddy, grayish midpoints. In oklch, mixing keeps chroma high but interpolates hue around the color wheel, so blending blue and yellow can pass through pink or green. The oklab space takes a straight path through the perceptual space, which gives clean tints and shades without unexpected hues. For mixing with white or black, I use oklab.

Wide gamut, without breaking sRGB screens

Many phones and laptops now show the Display P3 gamut, which holds more saturated colors than sRGB. oklch() can describe those colors directly; you simply use a higher chroma. On sRGB screens, the browser maps out-of-gamut colors back into range, reducing chroma while trying to keep lightness and hue.

:root {
  --brand: oklch(62% 0.19 255);          /* safely inside sRGB */
}

@media (color-gamut: p3) {
  :root {
    --brand: oklch(62% 0.24 255);        /* more vivid on capable screens */
  }
}

Keep text colors and anything tied to contrast inside sRGB, so the contrast you measured is the contrast every user gets. Spend the extra gamut on brand accents, illustrations and charts. Interactive pickers such as oklch.com show the sRGB and P3 boundaries for each hue, which makes finding the safe chroma limit quick.

contrast-color(): letting the browser pick text color

The contrast-color() function takes a background color and returns whichever of black or white contrasts more with it. Safari 26 and Firefox 146 shipped it in 2025, and Chrome 147 followed in 2026.

.tag {
  background: var(--tag-bg);
  color: contrast-color(var(--tag-bg));
}

It is perfect for user-chosen colors, such as labels in a project tracker. Know its limit: it only picks the better of black or white, and for mid-lightness backgrounds near L 57%, even the better choice may only just reach 4.5:1. Keep user-selectable backgrounds out of that middle band, or pair the function with a fallback color for older browsers.

Dark mode in oklch()

Dark themes need more than inverting lightness. Large areas of highly saturated color glow uncomfortably on dark backgrounds, so dark palettes usually lower chroma and raise the lightness of accents slightly. With oklch both adjustments are explicit numbers:

:root {
  color-scheme: light dark;
  --color-surface: light-dark(oklch(99% 0.005 255), oklch(20% 0.015 255));
  --color-text:    light-dark(oklch(22% 0.02 255),  oklch(93% 0.01 255));
  --color-accent:  light-dark(oklch(52% 0.19 255),  oklch(72% 0.14 255));
}

The dark accent is lighter for contrast against the dark surface and lower in chroma to avoid glare. Because hue stays at 255, it is still recognizably the same brand blue.

Frequently Asked Questions

What is oklch() in CSS?

oklch() is a CSS color function that specifies colors by perceived lightness, chroma and hue, based on the Oklab color model. Because its lightness matches human perception, colors with the same lightness value look equally light regardless of hue, which makes palettes and contrast far more predictable than with HSL.

Is oklch() better than HSL?

For building palettes and design systems, yes. HSL lightness is a mathematical reshaping of RGB and does not match perception, so a yellow and a blue at the same HSL lightness look very different. OKLCH lightness tracks perception, so scales and derived colors behave consistently across hues.

Is oklch() supported in all browsers?

Yes. oklch() and color-mix() have been supported in Chrome, Edge, Firefox and Safari since 2023, and relative color syntax since 2024. Browsers automatically map colors outside a screen’s gamut back into range.

Does oklch() guarantee accessible contrast?

No. WCAG contrast ratios are calculated from relative luminance, not OKLCH lightness. OKLCH lightness is a much better predictor than HSL, so it helps you plan palettes, but each text and background pair should still be checked against the WCAG 2.2 thresholds.

Choose colors by how they look

HSL asks you to think like a monitor. oklch() lets you think like a person looking at the screen. Define your palette in it, derive states with relative colors, mix in oklab, and verify contrast with a tool. The colors stay consistent long after the person who picked them has moved on. Next, the View Transitions API brings the same declarative approach to animation between states and pages.

Rule of thumb: if two colors at the same step look like they weigh differently, your color space is lying to you.

Originally posted on 23 April 2026 and post last modified on 23 April 2026

Accessibility Color CSS Front-End Development oklch

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *