記事一覧Related topics
CSS and gradients
How gradient syntax really works, why gradients turn muddy, and the fixes that keep them clean.
A CSS gradient is a generated image rather than a colour. That one fact explains most of its behaviour: why it belongs in background instead of background-color, and why it can be layered, sized and repeated like any other image.
The failure people hit most often is a gradient going grey in the middle. That is not a bug in your code — it is what happens when a browser interpolates between two saturated hues in sRGB, because the straight line between them passes through a desaturated region.
There are three fixes, and this section works through when each is the right one.
What you'll learn here
- How gradient angles are measured, and why 0deg points up.
- How to create a hard edge instead of a blend, without an image.
- Why fading to `transparent` produces a grey haze, and what to write instead.
- How to interpolate in OKLCH so the midpoint stays clean.









