Learn

Why RGB Gradients Look Muddy (and How to Fix It)

Most CSS gradients interpolate in sRGB by default. That single decision creates the grey band problem — a muddy, desaturated middle that makes gradients look dull.

The problem: sRGB interpolation

When you write linear-gradient(to right, red, blue), the browser mixes the two colors by linearly interpolating each RGB channel separately. Red in sRGB is rgb(255, 0, 0) and blue is rgb(0, 0, 255). At the 50% midpoint you get rgb(128, 0, 128) — a dark purple.

That works fine for similar hues. But whenever the hue shift is large — especially when going through the blue-green range or across complementary hues — the midpoint passes through low-saturation territory in sRGB space. The result is a grey, muddy band in the middle.

Why sRGB lies about equal steps

sRGB was designed to match the response of 1990s CRT monitors, not human perception. Equal numeric steps in sRGB don't look equal to the eye — the lightness changes non-uniformly, and hue purity varies across the color space.

A 50% mix between two saturated complementary colors in sRGB almost always falls in the least-saturated region of the color wheel (around grey). Human color perception, however, would expect a vivid intermediate hue.

The fix: use a perceptual color space

Modern CSS allows you to specify which color space to use for gradient interpolation:

/* Default — interpolates in sRGB (can look muddy) */
background: linear-gradient(to right, red, blue);

/* Better — interpolates in OKLab (perceptually uniform) */
background: linear-gradient(to right in oklab, red, blue);

/* Best for hue-spanning gradients — interpolates in OKLCH */
background: linear-gradient(to right in oklch, red, blue);

The in <colorspace> syntax was added in CSS Color Level 4 and is now supported in all modern browsers (Chrome 111+, Firefox 113+, Safari 16.2+).

OKLab vs OKLCH — which to use?

  • OKLab interpolates through Cartesian coordinates (a, b channels). Good for transitions where you want the hue to take the shortest path.
  • OKLCH interpolates hue, chroma, and lightness independently. Better for rainbow-style gradients spanning many hues — you can control whether the transition goes the "short way" or "long way" around the hue wheel.
/* Short hue arc (default) — always picks shortest hue distance */
background: linear-gradient(in oklch, to right, oklch(60% 0.25 30), oklch(60% 0.25 260));

/* Longer arc — goes the other way around the hue wheel */
background: linear-gradient(in oklch longer hue, to right, oklch(60% 0.25 30), oklch(60% 0.25 260));

Practical checklist

  • For gradients spanning <60° of hue, sRGB is usually fine.
  • For gradients spanning complementary colors (180° apart), always use in oklab or in oklch.
  • For deliberate rainbow transitions, use in oklch longer hue.
  • When in doubt, compare: render both versions side by side and pick the one that looks most vibrant.

What about older browsers?

The in <colorspace> syntax degrades gracefully — older browsers that don't understand it will ignore the declaration and fall back to whatever gradient was defined before it. Provide a plain sRGB gradient first as a fallback:

/* Fallback for older browsers */
background: linear-gradient(to right, #e63946, #457b9d);

/* Enhanced version for modern browsers */
background: linear-gradient(to right in oklch, #e63946, #457b9d);