🎨 CSS: Fix color-mix Producing a Muddy Unexpected Hue
color-mix() defaults to interpolating in the oklab color space unless you tell it otherwise, and while that produces perceptually smooth results for most pairs of colors, mixing two colors that sit on opposite sides of the hue wheel — a saturated blue and a saturated orange, say, used to build a ‘neutral’ middle tone for a design system — can pass through a visibly muddy, desaturated gray-brown at the midpoint, because the shortest interpolation path between two near-complementary hues in a perceptually uniform space runs straight through low-saturation territory rather than around the wheel.
🔎 The Problem
/* Trying to build a neutral middle tone between a brand blue and orange */
.swatch-midpoint {
background: color-mix(in oklab, #2563eb 50%, #f97316 50%);
/* Renders as a flat, muddy gray-brown - not the warm neutral the
design system expected, because oklab's shortest path between
these two hues crosses straight through near-zero saturation */
}
✅ Fix: Pick an Interpolation Color Space That Matches the Intent
- Switch to a polar (hue-based) color space like
oklchorhslwhen the goal is a smooth hue transition —color-mix(in oklch, #2563eb 50%, #f97316 50%)travels around the hue wheel instead of cutting through its desaturated center, landing on a visibly warmer, more saturated midpoint. - Reach for
srgb-linearor plainsrgbspecifically when blending for a brightness/luminance effect (like a tint or shade of a single base color) rather than a hue transition, since those spaces behave closer to how most designers already expect flat color blending to look from other tools. - Preview the actual midpoint color in a dedicated swatch during development rather than trusting the formula alone — the right color space genuinely depends on whether the two input colors are close in hue (any space works fine) or far apart (polar spaces avoid the muddy shortcut through gray).
🚨 Why This Is Dangerous
- A design system’s generated neutral or “between” tone that looks subtly wrong in oklab’s default interpolation can slip into a shared token file and propagate across every component that references it, so the fix needed is a one-word interpolation-space change, but the affected surface by the time it’s noticed can be the entire UI.
The shortest path between two colors isn’t always the one that looks right — and oklab’s default shortest path between near-complementary hues runs straight through the one color nobody asked for: gray.




