Why OKLCH is the Future of CSS Web Design
The way we write CSS colors is undergoing a major evolution. For decades, developers relied on hex codes, RGB, and eventually HSL. While HSL made color adjustments easier, it suffered from a fundamental flaw: it is not perceptually uniform.
The Perceptual Uniformity Flaw
In HSL, colors with the exact same lightness value look drastically different in brightness. For example, a pure yellow (hsl(60, 100%, 50%)) looks blindingly bright, while a pure blue (hsl(240, 100%, 50%)) looks incredibly dark, even though both have their lightness set to 50%.
This makes generating accessible, high-contrast color palettes dynamically almost impossible.
Enter OKLCH
OKLCH stands for Lightness (L), Chroma (C), and Hue (H). Unlike HSL, it is calibrated to human visual perception:
L≈Perceived brightness
This means that an OKLCH color with L=0.7 (70% lightness) will look exactly as bright to the human eye whether it is yellow, blue, green, or magenta!
Here is how you write a dynamic branding system in modern CSS using Tailwind CSS v4 and the light-dark() utility:
:root {
--accent-primary-light: oklch(55% 0.22 280); /* Electric Indigo */
--accent-primary-dark: oklch(75% 0.18 280); /* Lavender Light */
--accent-primary: light-dark(var(--accent-primary-light), var(--accent-primary-dark));
}
By adapting OKLCH, you unlock wide-gamut colors (supported by modern displays but completely unrepresentable in sRGB-constrained spaces like hex or HSL) and guarantee flawless contrast ratios across both light and dark modes!