Menu

Why your CSS gradients look muddy in the middle (and the one-word fix)
📰

Why your CSS gradients look muddy in the middle (and the one-word fix)

DEV Community: css·GoToolsOnline·16 days ago
#XpfffJnr
#devtocss#devto#dev#gradient#blue
Long article (261 words) — no AI summary yet.
Reading 0:00
15s threshold

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 ) ; }

Enter fullscreen mode

Exit fullscreen mode

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 hue to 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 ,…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.