CSS techniques

CSS gradients explained: linear, radial and conic

How linear, radial and conic gradients work in CSS, with copy-ready code for stripes, pie charts, text overlays and gradient borders, and how to stop blends turning muddy.

CSS has three gradient functions: linear-gradient() blends colours along a straight line at an angle, radial-gradient() spreads them outwards from a point in a circle or ellipse, and conic-gradient() rotates them around a centre like a colour wheel. Each has a repeating- version, all three work in every current browser, and because gradients count as images, you use them anywhere CSS accepts an image, most often background.

Key takeaways

  • Linear for directional fades, radial for glows and spotlights, conic for pie charts, colour wheels and angular effects.
  • Two colour stops at the same position make a hard line instead of a blend.
  • Add in oklch to avoid a muddy grey middle when blending very different colours.
  • Gradients cost no download and stay sharp at any size.

How does linear-gradient() work?

.hero {
  background: linear-gradient(135deg, #ff7a59, #7b5cff);
}

The first value is the direction, and it is optional; without it the gradient runs from top to bottom. It can be an angle (0deg points up, 90deg right) or a keyword such as to right or to bottom left. Then come the colour stops. With no positions, they are spaced evenly. Add a percentage to place a stop exactly, or a bare percentage between two colours to move the midpoint of the blend:

/* Orange holds until 20%, blend midpoint at 60% */
background: linear-gradient(90deg, #ff7a59 20%, 60%, #7b5cff);

How does radial-gradient() work?

.spotlight {
  background: radial-gradient(circle at 30% 20%, #ffd166, transparent 60%), #170c30;
}

You set the shape (circle or the default ellipse), optionally a size such as closest-side or farthest-corner, and the centre with at x y. Fading a colour to transparent over a solid background is the basis of glows, vignettes and soft lighting. Layering several of these is how CSS mesh gradients are made.

How does conic-gradient() work?

.pie {
  border-radius: 50%;
  background: conic-gradient(#ff7a59 0 40%, #ffd166 0 65%, #7b5cff 0);
}

Colours sweep around the centre instead of across the box. Each stop is an angle or a percentage of the full turn. The example is a pie chart: a stop position of 0 means “start where the previous colour ended”, so each segment has hard edges. Conic gradients also make colour wheels, loading rings and the shine on a metallic button.

Which gradient type should you use?

TypeLooks likeGood for
linearA straight fadeHero backgrounds, buttons, overlays on photos
radialA glow from a pointSpotlights, vignettes, soft lighting, mesh gradients
conicA sweep around a centrePie charts, colour wheels, angular shine, borders
repeating-linearStripesProgress bars, warning tape, backgrounds
repeating-radialRingsRipples, targets, retro patterns
repeating-conicRays or checkerboardsSunbursts, transparency grids

How do you make hard stripes with a gradient?

Put two colour stops at the same position and the browser draws a sharp line instead of a blend. Combined with a repeating gradient, that makes stripes with no image at all. Change the pixel values to make the stripes wider or narrower:

.stripes {
  background: repeating-linear-gradient(
    45deg,
    #ffd166 0 12px,
    #1a1020 12px 24px
  );
}

Two everyday gradient tricks

Readable text over a photo

A dark gradient from the bottom of a hero image makes white text readable without darkening the whole photo. Layer it above the image in the same background, so the gradient comes first in the list:

.hero {
  background:
    linear-gradient(to top, rgb(0 0 0 / .7), transparent 60%),
    url("hero.webp") center / cover;
}

Gradient borders with rounded corners

border-image ignores border-radius, so use two backgrounds instead: a solid colour clipped to the padding box, and the gradient clipped to the border box. The gradient shows through only where the transparent border is.

.card {
  border: 2px solid transparent;
  border-radius: 16px;
  background:
    linear-gradient(#1a1020, #1a1020) padding-box,
    linear-gradient(135deg, #ff7a59, #7b5cff) border-box;
}

How do you stop gradients looking muddy?

By default, browsers blend gradients in the sRGB colour space. Blending two very different hues, such as orange and blue, passes through a dull grey-brown in the middle. Three fixes:

  • Interpolate in OKLCH: linear-gradient(in oklch 90deg, #ff7a59, #2f8cff) keeps the middle bright. It is supported in all current browsers; older ones ignore the whole declaration, so put a plain gradient before it as a fallback.
  • Add a middle stop with a colour that sits between the two on the colour wheel.
  • Choose neighbouring hues, such as orange to pink or teal to blue, which blend cleanly in any space.

Banding: Large, smooth gradients can show visible bands of colour on some screens. A faint layer of noise hides them; see adding grain to CSS gradients.

Can you animate a CSS gradient?

Not directly: browsers can’t transition between two gradient images. Two workarounds do the job. Make the gradient larger than the element with background-size: 200% and animate background-position, or register the colours or angle as custom properties with @property, which lets the browser interpolate them. Our guide to gradient text uses the first approach for a shimmering heading. Either way, add a prefers-reduced-motion rule.

Build a gradient

The CSS gradient generator builds linear, radial and conic gradients with two or three stops, lets you move the midpoint and angle, and copies a ready-to-use rule. Its “Paste into” menu rewrites the code for Elementor, Divi, Bricks, Breakdance or the block editor. For layered, organic blends, try the mesh gradient generator.

Last checked: October 2026.

Sources: MDN: linear-gradient(), MDN: conic-gradient(), MDN: <color-interpolation-method>.