Menu

Why your CSS gradients go grey in the middle (and the one keyword that fixes it)
📰

Why your CSS gradients go grey in the middle (and the one keyword that fixes it)

DEV Community: css·Reflected DotCom·about 11 hours ago
#qIzYPaAO
#devtocss#devto#dev#oklch#gradient
Long article (893 words) — no AI summary yet.
Reading 0:00
15s threshold

Put this in a page and look at the middle of it:

.bar { background : linear-gradient ( to right , #0000ff , #ffff00 ) ; }

Enter fullscreen mode

Exit fullscreen mode

Blue on the left, yellow on the right, and right in the centre a flat, muddy grey. Nobody picked that grey. It is a side effect of how the browser blends the two colours.

Where the grey comes from

By default, a gradient between two hex colours is blended in sRGB. The browser takes the red, green and blue channels and moves each one in a straight line.

R G B

Start #0000ff 0 0 255

Middle 128 128 128

End #ffff00 255 255 0

The halfway point is #808080 , a perfect neutral grey. Any two colours that sit opposite each other on the wheel do this: blue and yellow, red and cyan, purple and green. The channels cancel out on the way across.

It is not a bug.…

Continue reading — create a free account

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