CSS Gradient Generator · Tutorial
How to make a gradient without the grey middle
6 min readintermediateUpdated
You set a gradient from blue to yellow for a banner, and the middle came out a dull grey-green. This tutorial shows why it happens, fixes it with the OKLCH option, and turns the result into CSS that works in every browser.
What you need
- The CSS Gradient Generator
- Two colours, or the sample from the Try it button
Steps
Build the plain gradient
Choose Linear, set the angle to 90° (left to right), and use two stops,
#0000ffat 0% and#ffff00at 100%. Untick Smoother blend (OKLCH) for now. The middle of the preview looks grey.Understand the grey
Browsers blend each red, green and blue channel separately in sRGB. Halfway between pure blue and pure yellow, all three channels are about equal, which is grey. The same happens with other opposite colours.
Switch on OKLCH blending
Tick Smoother blend (OKLCH). The CSS now contains
in oklch, and the blend travels around the colour wheel through bright greens and cyans instead of grey.background: #0000ff; background: linear-gradient(in oklch 90deg, #0000ff 0%, #ffff00 100%);Compare the alternative
If you need the same look in older browsers too, add a middle stop by hand instead: press Add a stop and choose a bright green at 50%. This avoids the grey without relying on OKLCH.
Copy the CSS
Press Copy. The first line is a solid fallback for very old browsers. Browsers that don’t know
in oklchignore the gradient line, so if you need it everywhere, use the extra-stop version.
Try it yourself
Opens the CSS Gradient Generator with this tutorial's sample loaded.
Common mistakes
- Expecting it in old browsers
in oklchneeds browsers from 2023 or later. Older browsers skip the whole declaration and use the fallback colour.- Using hex with transparency in stops
- Blending to
transparentcan show a dark fringe in some older browsers. Fade to the same colour with zero opacity instead, such asrgb(0 0 255 / 0). - Forgetting the angle direction
- 0° points up and 90° points right. If the colours appear the wrong way round, add 180°.
Next steps
Go back to the CSS Gradient Generator, or keep going with one of these:
FAQ
Does OKLCH blending work in radial and conic gradients?
Yes. The option applies to all three types.
Can I animate a gradient?
You can animate its position with background-position on a larger background, or use CSS custom properties registered with @property.