HTML Formatterhtmlformatteronline.com

CSS gradient generator

Build a gradient visually and copy the CSS. Linear, radial and conic, with a solid-colour fallback line included.

Type
Colour stops

Position is a percentage along the gradient.

Preview
CSS

The three gradient types

↗

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.

◎

Radial

Colours spread outward from a point. Good for spotlights, soft vignettes and glow effects behind a hero element.

◔

Conic

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.

Why so many gradients look muddy

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.

Progressive enhancement
.hero {
  background: linear-gradient(135deg, #3B4FE4, #E8A33D);
  background: linear-gradient(in oklch 135deg, #3B4FE4, #E8A33D);
}

Hard stops and stripes

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.

Stripes with no image
.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.

Gradient text

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.

Set a solid 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.

Performance and accessibility

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.

Questions about this generator

Why does my gradient look banded?

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.

Do I need vendor prefixes?

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.

What is the fallback line for?

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.

Can I animate a gradient?

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.

How do I use a gradient as a border?

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.

Related tools

Learn the why, not just the how

Longer reading on formatting, indentation and minification.