OKLCH Colors in CSS: A Practical Guide
October 2, 2026 | 9 min read | CSS
By Syed · Frontend Engineer & Creator of UITweak
Hex codes lie to you. #3b82f6 and #22c55e look like equally strong colors, but one reads far darker than the other. RGB was designed for screens, not for human eyes. OKLCH is a color space designed around perception: its three numbers map to how bright, how vivid, and which hue a color actually looks. The result is palettes that behave predictably and gradients that stay vivid instead of turning muddy.
Shortcut: experiment with rich multi-stop gradients in our free Mesh Gradient Generator, then apply the OKLCH techniques below to keep every stop perceptually uniform.
1. What the Three Numbers Mean
Every OKLCH color has three components, and each one does exactly what it says:
- L: Lightness from 0 (black) to 1 (white).
0.5looks middle gray for any hue. - C: Chroma, how vivid the color is.
0is gray, higher values are more saturated. Most UI colors sit between0.05and0.2. - H: Hue in degrees,
0to360, like a color wheel.
/* vivid blue, medium lightness */
.brand {
color: oklch(0.55 0.18 250);
}
/* same hue and lightness, muted */
.brand-muted {
color: oklch(0.55 0.06 250);
}
/* same hue and chroma, darker */
.brand-dark {
color: oklch(0.35 0.18 250);
}Notice how readable that is compared to hex. Want a darker variant? Lower L. Want it muted? Lower C. The numbers mean something, so you stop guessing.
2. Why Palettes Become Trivial
The classic palette problem: you pick five shades of blue in hex, and step 3 looks darker than step 4. In RGB, equal numeric steps are not equal visual steps. In OKLCH, fixing H and C while stepping L evenly gives you a scale where every step looks equally spaced:
:root {
--blue-100: oklch(0.92 0.04 250);
--blue-300: oklch(0.78 0.09 250);
--blue-500: oklch(0.62 0.14 250);
--blue-700: oklch(0.46 0.14 250);
--blue-900: oklch(0.32 0.10 250);
}Same hue family, chroma rising toward the middle then easing off for the darkest step (very dark vivid colors look neon, so pulling chroma back keeps them usable). This is the entire technique behind professional design-system palettes, and it fits in five lines.
3. Vivid Gradients with in oklch
The most visible win is in gradients. When CSS interpolates between two hex colors, it walks through RGB space, which passes through grayish, washed-out middle tones. Interpolating in OKLCH space instead keeps the saturation alive through the middle of the gradient:
/* dull middle: interpolates through grayish RGB */
.fade {
background: linear-gradient(to right, #3b82f6, #ec4899);
}
/* vivid middle: interpolates in perceptual space */
.vivid {
background: linear-gradient(in oklch to right, #3b82f6, #ec4899);
}Two words, in oklch, and the same two endpoints produce a noticeably richer gradient. This works for radial-gradient and conic-gradient too. If you build Stripe-style mesh backgrounds, our mesh gradient guide pairs well with this technique.
4. Using OKLCH in Tailwind v4
Tailwind v4 ships its default palette in OKLCH, which is why v4 colors look slightly richer than v3. You can define your own tokens the same way with @theme:
@import "tailwindcss";
@theme {
--color-brand-500: oklch(0.62 0.14 250);
--color-brand-700: oklch(0.46 0.14 250);
}
<!-- utilities work as usual -->
<button class="bg-brand-500 hover:bg-brand-700">
Get started
</button>Because the tokens are OKLCH, opacity modifiers like bg-brand-500/50 use color-mix and stay perceptually correct. For the full theming system, see our Tailwind v4 @theme guide.
5. Fallbacks for Older Browsers
OKLCH is supported in all modern browsers since 2023. For anything older, declare a hex fallback first, then let supporting browsers override it:
.brand {
color: #3b82f6; /* fallback */
color: oklch(0.62 0.14 250);
}
/* or gate a whole block */
@supports (color: oklch(0.5 0.1 250)) {
:root {
--brand: oklch(0.62 0.14 250);
}
}Browsers that do not understand OKLCH ignore the declaration they cannot parse and keep the fallback. No broken pages, just slightly less vivid colors on old engines.
6. Converting Your Existing Hex Palette
You do not need to redesign anything. Convert each hex to OKLCH (any converter tool does this in one click), then round the numbers to two decimals and nudge: even out the lightness steps, and pull back chroma on the darkest shades. Most teams convert their palette in an afternoon and immediately get more predictable results when they add new shades later.
Hue Interpolation: Which Way Around the Wheel
in oklch keeps gradients vivid, but it still has to decide which direction to travel between two hues. The default is the shorter arc. Sometimes you want the long way around, through every hue in between:
/* short way: red to blue through purple */
.short {
background: linear-gradient(in oklch to right, oklch(0.62 0.22 30), oklch(0.62 0.22 270));
}
/* long way: red to blue through orange, yellow, and green */
.long {
background: linear-gradient(in oklch longer hue to right, oklch(0.62 0.22 30), oklch(0.62 0.22 270));
}CSS Color 4 defines four hue interpolation methods: shorter hue (the default), longer hue, increasing hue, and decreasing hue. Increasing and decreasing force a clockwise or counterclockwise sweep even when the short arc goes the other way. I use longer hue for rainbow progress bars and color-wheel pickers, and I leave the default alone for brand gradients, where the short path is almost always what the designer intended. All current browsers support these keywords.
Out-of-Gamut Colors Clip Without Warning
OKLCH can describe colors no screen can display. Push chroma high at very low or very high lightness and the value falls outside the sRGB gamut. Browsers handle this by clamping to the nearest displayable color, silently. Your carefully stepped scale flattens at the ends and you blame your eyes.
Two practical defenses. First, Chrome and Safari DevTools show a gamut warning in the color picker when the picked color is out of gamut for the target space. If you see it, nudge chroma down until the warning clears. Second, keep a simple rule of thumb while authoring: the further lightness strays from the middle, the less chroma the gamut allows. A vivid oklch(0.9 0.2 250) will not survive on an sRGB screen; oklch(0.9 0.06 250) will.
Gradients deserve the same suspicion. Two in-gamut endpoints can still pass through out-of-gamut territory in the middle, and the clamped middle renders as a flat band. When a gradient band looks posterized, check the midpoint color in DevTools before blaming banding.
In practice I convert the palette, open each token in the DevTools picker, and fix every gamut warning before shipping. It takes ten minutes and it is the difference between a scale that looks intentional and one that quietly flattens at the ends. Treat the picker warning as a lint error, not a suggestion.
Deriving Tints and Shades with color-mix()
Hand-maintaining a nine-step scale is overkill when you need one lighter variant for a hover state. Derive it:
:root {
--brand: oklch(0.62 0.14 250);
--brand-hover: color-mix(in oklch, var(--brand) 88%, black);
--brand-tint: color-mix(in oklch, var(--brand) 12%, white);
--brand-wash: color-mix(in oklch, var(--brand) 8%, transparent);
}Mixing in OKLCH keeps the hue stable while lightness and chroma move, which is exactly what a tint should do. Mixing the same colors in sRGB often drifts the hue, especially with blues and purples. My rule: documented palette scales get hand-tuned tokens; one-off states get color-mix(). It keeps the token list short and every derived color stays in the same hue family by construction.
Relative Colors for Programmatic Variants
When the variant is a mechanical transform of a base color, say so in the code instead of hardcoding a second value:
.card {
--brand: oklch(0.62 0.14 250);
background: var(--brand);
/* same hue and chroma, 12 points darker */
border-color: oklch(from var(--brand) calc(l - 0.12) c h);
}
.card:hover {
/* same lightness and chroma, hue rotated for an accent shift */
background: oklch(from var(--brand) l c calc(h + 40));
}The from syntax decomposes any color into OKLCH components you can adjust with calc(). It accepts hex, rgb, and variables alike, so it works on tokens you did not author. I use it for hover darkening, focus rings derived from border colors, and disabled states. One limit: it computes at used-value time, so DevTools shows the formula rather than the resolved color, which makes debugging slightly harder. Supported in all modern browsers since 2024.
Frequently Asked Questions
Is OKLCH better than HSL?
For UI work, yes. HSL lightness is not perceptual either: hsl(0 100% 50%) red and hsl(240 100% 50%) blue have the same lightness value but look very different in brightness. OKLCH fixes exactly that.
Do I need OKLCH if I use Tailwind?
Tailwind v4 already uses it under the hood for the default palette. You benefit automatically, and defining custom tokens in OKLCH keeps your additions consistent with the built-ins.
What is "in oklch" in a gradient?
It tells the browser to interpolate the gradient's color stops in OKLCH space instead of the default sRGB space. The endpoints stay the same; the middle gets more vivid and even.
Is OKLCH safe to use in 2026?
Yes. All modern browsers support it, and the hex-fallback pattern above covers anything older. It is one of the safest modern CSS features to adopt.
Try it now: build a multi-stop gradient in the free Mesh Gradient Generator, convert your palette stops to OKLCH, and add in oklch interpolation for visibly richer color.
Try it: related UI elements
Lightning fast
Optimized for speed with edge rendering and smart caching. Pages load in milliseconds, not seconds.
Learn moreFeature Card
Copy code →
Star Rating
Copy code →
Success. Your profile has been updated.
Warning. Your trial ends in 3 days.
Error. Payment failed. Try again.
Info. New features are available.
Alert Banner
Copy code →
Status Dot
Copy code →