Code

The CSS Gradient Syntax Guide

Linear, radial and conic gradients explained with copy-ready examples: angles, stops, hard edges, repeats and layering.

By The White Screen Background crew4 min read
The CSS Gradient Syntax GuideCodeThe CSS GradientSyntax Guide

CSS gradients are images made by the browser. No files, no downloads, infinitely sharp. Once you know the syntax you can build backgrounds, patterns, borders and even charts with a single line. Here’s everything you need, with examples you can paste straight in.

Linear gradients

The one you’ll use most. Colours blend along a straight line.

background: linear-gradient(120deg, #3B82F6, #EC4899);

The first value is the direction. Then come the colours, called colour stops.

Direction

  • Angles: 0deg points up, 90deg points right, 180deg points down. Angles go clockwise.
  • Keywords: to right, to bottom, to top left.
  • Default: leave it out and you get top to bottom, the same as 180deg.

One gotcha: to top right aims at the corner, so its angle depends on the box’s shape. 45deg is always 45 degrees.

Colour stops

Each colour can have a position. Without positions, stops are spread evenly.

background: linear-gradient(90deg, #3B82F6 0%, #8B5CF6 30%, #EC4899 100%);

Here the purple arrives early, at 30 percent, so most of the box is purple-to-pink.

Hard edges

Put two stops at the same position and the blend becomes a sharp line. That’s how you make stripes.

background: linear-gradient(90deg, #3B82F6 50%, #EC4899 50%);

Two-position stops

A colour can have a start and end position, giving it a solid band:

background: linear-gradient(90deg, #3B82F6 0% 33%, #8B5CF6 33% 66%, #EC4899 66% 100%);

Colour hints

A lone percentage between two colours moves the midpoint of the blend:

background: linear-gradient(90deg, #3B82F6, 20%, #EC4899);

Radial gradients

Colours spread outward from a point.

background: radial-gradient(circle at 30% 20%, #FFD6E7, #E6E0FF);
  • Shape: circle or ellipse (the default).
  • Position: at center, at top left, or any x and y.
  • Size: closest-side, farthest-corner (the default), or explicit lengths like circle 200px.

Fade a radial gradient to transparent and layer a few of them to get soft, organic blobs. That’s the core of mesh gradients.

Conic gradients

Colours sweep around a centre point, like a colour wheel or a pie chart.

background: conic-gradient(from 0deg at 50% 50%, #3B82F6, #8B5CF6, #EC4899, #3B82F6);

Repeat the first colour at the end for a seamless loop. With hard stops, conic gradients make pie charts and checkerboards.

Repeating gradients

Add repeating- and the pattern tiles forever.

background: repeating-linear-gradient(45deg, #E2E8F0 0 2px, transparent 2px 12px);

That’s diagonal pinstripes in one line. There’s also repeating-radial-gradient and repeating-conic-gradient.

Layering gradients

A background can hold several images, separated by commas. The first one is on top.

background:
  radial-gradient(circle at 20% 20%, rgba(59,130,246,.4), transparent 50%),
  radial-gradient(circle at 80% 30%, rgba(236,72,153,.4), transparent 50%),
  #FFFFFF;

Use transparency so lower layers show through. A solid colour can only go last.

Patterns with background-size

A gradient fills the box by default. Shrink it with background-size and it repeats as a tile.

PatternCSS
Dotsradial-gradient(#CBD5E1 2px, transparent 2px) with background-size: 24px 24px
Gridlinear-gradient(#CBD5E1 1px, transparent 1px), linear-gradient(90deg, #CBD5E1 1px, transparent 1px) with background-size: 24px 24px
Stripesrepeating-linear-gradient(45deg, #CBD5E1 0 3px, transparent 3px 12px)

The studio writes all of these for you, plus triangles and noise.

The transparent trap

Fading a colour to the keyword transparent used to produce a grey smudge in some browsers, because transparent is technically transparent black. Modern browsers handle it well, but if you see a dirty fade, use the same colour with zero alpha instead: rgba(59,130,246,0).

Smoother blends with colour spaces

Modern browsers let you choose the colour space a gradient blends in:

background: linear-gradient(in oklch, #3B82F6, #EC4899);

Blending in oklch or oklab often gives more vivid, even transitions, with no muddy middle. Add a plain gradient first as a fallback for older browsers:

background: linear-gradient(90deg, #3B82F6, #EC4899);
background: linear-gradient(90deg in oklch, #3B82F6, #EC4899);

Gradient text

h1 {
  background: linear-gradient(120deg, #3B82F6, #8B5CF6, #EC4899);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

Keep it for large headings, and check it’s readable; see accessible colour contrast.

Performance and gotchas

  • Gradients are cheap to draw, far lighter than image files.
  • You can’t transition between two gradients directly. Animate background-position on an oversized gradient, or cross-fade two layers with opacity.
  • Gradients are images, so use background or background-image, not background-color.
  • Long, dark gradients can show banding. A little noise fixes it; see gradients that look expensive.

Cheat sheet

linear-gradient(angle, color pos, color pos)
radial-gradient(shape size at x y, color, color)
conic-gradient(from angle at x y, color, color)
repeating-linear-gradient(angle, color a b, color b c)

That’s the lot. Build one visually in the studio, hit Copy CSS, and paste.

A good way to learn all this is to break things on purpose. Open the studio, copy a gradient, paste it into your browser’s developer tools and start changing numbers. Swap an angle, move a stop to 10 percent, add a second layer. You’ll build an instinct for the syntax far faster than by reading, and you’ll stumble on a few happy accidents worth keeping. When you find one you love, drop it in a CSS custom property so you can reuse it across your whole site.

Bookmark this page for the next time an angle points the wrong way. It happens to all of us.

FAQ

0deg points up and angles increase clockwise, so 90deg points right and 180deg points down.

Not directly between two gradients. Animate background-position on a larger gradient or cross-fade layers.

As many as you like, though two or three usually look best.

Keep reading

Partner with us

Get your brand in front of creators

We run a few clearly labelled sponsored links, featured tool spots and newsletter shout-outs for design tools, streaming gear and creator apps. If our readers would actually use it, let’s talk.

One email a month. No spam, unsubscribe any time.