Linear
Colours travel in a straight line at whatever angle you set. 0deg goes bottom to top, 90deg left to right. The one you want nine times out of ten.
Build a gradient visually and copy the CSS. Linear, radial and conic, with a solid-colour fallback line included.
Colours travel in a straight line at whatever angle you set. 0deg goes bottom to top, 90deg left to right. The one you want nine times out of ten.
Colours spread outward from a point. Good for spotlights, soft vignettes and glow effects behind a hero element.
Colours sweep around a centre point like a clock face. This is how you build a pie chart, a colour wheel or a progress ring in pure CSS.
Browsers interpolate between your colours in sRGB by default, and sRGB has a dead zone. Blend blue into yellow and the midpoint comes out grey rather than green.
Three ways round it, in increasing order of effort:
Add a midpoint stop. Pick the colour you actually want in the middle and place it at 50%. Works everywhere, no new syntax.
Use similar hues. Gradients between neighbouring colours on the wheel never go muddy, because there is no dead zone to cross. This is why blue-to-purple looks good with no effort at all.
Interpolate in a better colour space. Modern CSS lets you say
linear-gradient(in oklch, blue, yellow), and OKLCH keeps perceived lightness constant across the
blend. Support is good in current browsers but not universal, so keep a plain version as the preceding
declaration.
.hero {
background: linear-gradient(135deg, #3B4FE4, #E8A33D);
background: linear-gradient(in oklch 135deg, #3B4FE4, #E8A33D);
}
Put two stops at the same position and the transition becomes a hard edge. That single trick covers stripes, progress bars, split backgrounds and sectioned buttons — no images, no extra elements.
.striped {
background: repeating-linear-gradient(
45deg,
#3B4FE4 0 10px,
#2A3ABF 10px 20px
);
}
Tick Repeating above and set two stops close together to build this visually.
Tick Apply to text and the gradient is clipped to the glyphs instead of filling the box.
It needs three declarations together, and the -webkit- prefix is still required even in browsers
that support the standard property.
color first as a fallback. If background-clip
fails and the colour is already transparent, the text disappears entirely — invisible to sighted readers
while still present for search engines, which is exactly the pattern that looks like cloaking.Gradients are cheap to paint and cost nothing to download, which makes them strictly better than a
background image for the same effect. The exception is animating one: background is not a
GPU-accelerated property, so animating gradient stops repaints every frame. Animate
background-position on an oversized gradient instead, or animate opacity on a
stacked layer.
For text over a gradient, check contrast at both ends. A headline that passes on the dark end of a gradient often fails on the light end, and automated checkers only sample one point. Test the worst case, not the average.
Banding happens when there are not enough distinct colours between your stops to fill the distance smoothly — most visible on large areas with a subtle gradient. Adding a very slight noise overlay hides it, and so does using stops that are further apart in value.
Not for gradients. linear-gradient, radial-gradient and conic-gradient all work unprefixed in every browser in current use. You do still need -webkit-background-clip for gradient text.
Browsers that do not understand a declaration ignore it and keep the previous one. The solid colour first means a very old browser shows a plain background rather than nothing. It costs one line and there is no reason to omit it.
Not the stops themselves — they are not interpolatable properties in most browsers. The usual technique is to make the gradient much larger than its box and animate background-position, which gives the same visual effect and stays cheap.
border-image works but disables border-radius. For a rounded gradient border, use a background gradient with padding and an inner element, or background-origin with two stacked backgrounds — the second is fiddly but keeps the markup clean.
Lay out stylesheets with consistent indentation.
OpenCompress stylesheets for production.
OpenLayer CSS shadows and copy the result.
OpenBuild a full head block with a live search and social preview.
OpenProduce valid JSON-LD for rich results.
OpenWrite crawl rules without guessing the syntax.
OpenLonger reading on formatting, indentation and minification.