Blend blue into yellow with linear-gradient(90deg, blue, yellow) and the middle turns a dull grey. That isn't your colours' fault: by default browsers mix gradient colours in sRGB, where the straight line between two colours often passes through a desaturated zone.
The fix: interpolate in OKLab or OKLCH
.muddy { background: linear-gradient(90deg, blue, yellow); }
.clean { background: linear-gradient(in oklab 90deg, blue, yellow); }
.vivid { background: linear-gradient(in oklch 90deg, blue, yellow); }
- oklab is perceptually even, so the midpoint looks like a real halfway colour.
-
oklch travels around the hue wheel, giving brighter, rainbow-like transitions (use
shorter hue/longer hueto choose the direction).
Keep a fallback
Colour-space interpolation is supported in current Chrome, Edge, Firefox and Safari, but declare the plain version first so older browsers still get a gradient:
.card {
background: linear-gradient(90deg, blue, yellow);
background: linear-gradient(in oklab 90deg, blue, yellow);
}
Two more tips
- Add a middle stop instead of fighting the blend:
linear-gradient(90deg, blue, #6aa 50%, yellow). -
conic-gradient()works great for pie charts and colour wheels:conic-gradient(red 0 25%, gold 0 60%, teal 0).
Try it
Disclosure: I run GoToolsOnline. Its free CSS gradient generator does linear, radial and conic gradients with draggable stops and an OKLab/OKLCH option, and writes the fallback line for you: https://gotoolsonline.com/tools/css-gradient
Top comments (0)