CSS and web

CSS radial gradient: shapes, sizes and positions

radial-gradient() draws colour outwards from a point. Here is every part of it, with live examples, plus the layering tricks behind soft glows, spotlights and vignettes.

GradientlyVerified Gradiently account··5 min read
Cover: Cinder Ribbon · GR·3GXC·C6

The short version

  • A CSS radial gradient spreads colour outwards from a centre point, and is written with the radial-gradient() function anywhere CSS accepts an image.
  • By default a radial gradient is an ellipse, centred in the box, sized to reach the farthest corner.
  • The size keywords closest-side, closest-corner, farthest-side and farthest-corner decide where the last colour stop lands.
  • The at keyword moves the centre, for example at 20% 30%, and positions work like background-position.
  • Layering several radial gradients that fade to transparent is the standard way to build soft glows and mesh-like backgrounds in CSS.
On this page

A CSS radial gradient blends colour outwards from a point, like light spreading from a lamp. You write it with radial-gradient() and use it wherever CSS takes an image, usually background-image. With no options it draws an ellipse in the middle of the box that reaches the farthest corner: radial-gradient(#fef3c7, #b45309) gives a pale centre glowing out to deep amber.

Amber glow, all defaultsradial-gradient(#fef3c7, #f59e0b 45%, #78350f)
An ellipse, centred, sized to the farthest corner. That is what you get when you only give colours.

Everything else in the function changes one of three things: the shape, the size and the position. Once you can control those, the same function draws glows, spotlights, vignettes, sunbursts and the colour pools behind a mesh gradient in CSS. For the design side of radial blends, see the companion guide to radial gradients.

The radial-gradient() syntax

css
/* shape  size          position        stops */
radial-gradient(circle closest-side at 30% 40%, #fde047, #ea580c 60%, #1c1917)

/* everything before the first comma is optional */
radial-gradient(#fde047, #ea580c)
Shape and size can come in either order. The position always follows the word at.
PartValuesDefault
Shapecircle or ellipseellipse
Sizea keyword, one length for a circle, or two lengths or percentages for an ellipsefarthest-corner
Positionat followed by anything background-position acceptsat center
Interpolationin oklab, in oklch and other colour spacessRGB for hex colours
Colour stopstwo or more colours with optional positionsrequired
The parts of radial-gradient(). Only the colour stops are required.

One rule catches people out: a circle's size must be a length such as 200px, never a percentage, because a percentage of a rectangle has no single radius. Ellipses accept percentages, as in ellipse 60% 40%. The MDN reference for radial-gradient() lists the full grammar.

Circle versus ellipse

An ellipse stretches with the box, so on a wide banner the glow is wide and on a tall story it is tall. A circle stays round whatever the box does. Use ellipses for backgrounds that should fill their container evenly, and circles for anything that should read as a light source, a planet or a button's glow.

The same mint to forest stops. On a wide tile, the ellipse spreads sideways and the circle does not.

Size keywords: closest-side to farthest-corner

The size decides where the final colour stop lands, which is where the gradient's ending shape sits. The four keywords measure from the centre to the nearest or farthest side or corner of the box. They only look different when the centre is off-centre, so the examples below all start at 30% 40%.

One sun, four sizes. closest-side ends at the nearest edge; farthest-corner, the default, reaches the corner furthest away.

In practice, closest-side suits contained shapes such as dots and badges, because the colour never runs off the nearest edge. farthest-corner suits backgrounds, because the blend covers the whole box. When you need exact control, give a length: circle 180px at 50% 0 is a 180 pixel glow hanging from the top edge.

Positioning with at

The at keyword places the centre using the same values as background-position: keywords like at top right, percentages like at 20% 80%, or lengths like at 40px 60px. The centre can even sit outside the box, as in at 50% 120%, which gives a horizon glow rising from below the bottom edge.

Moving the centre changes the mood more than changing the colours does.

Layered radial glows

The most useful radial pattern is several gradients stacked in one background-image, each fading to transparent, over a flat dark colour. Each layer is a pool of light in its own place. Because the first layer is painted on top, put the brightest, smallest glow first.

css
.glow {
  background-color: #0b0a1a;
  background-image:
    radial-gradient(circle at 20% 25%, rgb(124 58 237 / 0.55), transparent 45%),
    radial-gradient(circle at 80% 30%, rgb(236 72 153 / 0.45), transparent 40%),
    radial-gradient(ellipse at 50% 110%, rgb(56 189 248 / 0.4), transparent 60%);
}
Three pools of violet, pink and sky blue on a near-black ground. Change a position and the whole composition shifts.

Two more patterns cover most remaining jobs. A vignette darkens the edges: radial-gradient(ellipse, transparent 55%, rgb(0 0 0 / 0.55)) layered over a photo. A spotlight follows the pointer when you feed its position from custom properties, such as radial-gradient(circle 240px at var(--x) var(--y), rgb(255 255 255 / 0.15), transparent), with a few lines of JavaScript setting --x and --y on pointermove.

Repeating radial gradients

repeating-radial-gradient() repeats its stops outwards until the box is full, so a pair of hard stops becomes rings. Use lengths for the stop positions so the ring width stays constant. It is the basis of ripple, target and halftone-like textures, and the CSS patterns guide has more.

Hard stops at fixed lengths turn a radial gradient into rings.

Avoid

  • Percentages for a circle's size, which are invalid
  • Bright glows that end in a hard edge because the last stop is opaque
  • Centring every glow at 50% 50%
  • Five overlapping glows of equal strength

Do

  • Lengths for circles, percentages for ellipses
  • Fade each glow to transparent
  • Place glows off-centre, near corners or below the edge
  • One dominant glow and one or two quieter ones

Questions people ask

How do I make a circle gradient in CSS?

Use radial-gradient(circle, colour1, colour2). Adding circle keeps the shape round; without it you get an ellipse that stretches with the box.

How do I move the centre of a radial gradient?

Add at and a position after the shape and size, for example radial-gradient(circle at 20% 30%, #c4b5fd, #1e1b4b). Positions work like background-position.

What does farthest-corner mean?

It sizes the gradient so its last colour stop reaches the corner of the box furthest from the centre. It is the default size.

Can a circle radial gradient use a percentage size?

No. A circle needs a single length such as 200px. Ellipses can use two percentages, such as ellipse 60% 40%.

How do I make a glow effect with CSS gradients?

Layer one or more radial-gradient() values that fade from a semi-transparent colour to transparent, over a dark background-color.

Share this guide

Written by GradientlyVerified Gradiently account

The team behind Gradiently, a design tool built around Marks: living gradients that make everything you design look like yours.

See our profile