radial-gradient()

Creates a colour transition radiating outwards from a point, along a circle or an ellipse. Good for glows, vignettes, and soft lights.

On this page

Example

#
CSS
.card {
  background:
    radial-gradient(circle at 15% 20%, rgb(124 58 237 / 0.55), transparent 45%),
    radial-gradient(circle at 85% 80%, rgb(14 165 233 / 0.45), transparent 45%),
    #111114;
}
Preview

The two blurred patches of light in the card’s corners are two radial gradients with transparent ends, laid over a dark background colour.

Definition and usage

#

The radial-gradient() function draws colours radiating from the centre, like ripples on water. The first colour sits at the starting point and the last at the edge of the shape. Like linear-gradient() it creates an image, so you use it in background or background-image.

The shape is ellipse (the default, matched to the element’s proportions) or circle. The size is set by keywords: farthest-corner (the default, the gradient reaches the farthest corner), closest-side, closest-corner, and farthest-side, or by concrete dimensions, for example circle 80px or ellipse 60% 40%.

You move the centre with the word at: radial-gradient(circle at top left, …) or at 30% 70%. The order is fixed: first the shape and size, then at with the position, and only after a comma the colours, for example radial-gradient(circle 120px at 20% 30%, #7c3aed, transparent).

In practice several such gradients with transparent ends are often layered to get coloured, blurred patches of light in the background. A single gradient also works well as a vignette that darkens the edges of a photo. The repeating-radial-gradient() version repeats the rings.

Syntax

#
Syntax
radial-gradient([<shape> <size>]? [at <position>]?, <color> <position>?, <color> <position>?, …)

Syntax variants

#
  • #7c3aed, #18181b

    ellipse from the centre

    With no extra settings the gradient is an ellipse matched to the element and starts at its centre.
  • circle

    circle

    The word circle forces a circle, regardless of the element’s proportions.
  • circle at top left

    centre in a corner

    After at you give the position of the centre. The light falls from the top left corner.
  • circle closest-side

    to the nearest side

    The gradient ends at the nearest edge of the element, so in a wide rectangle it creates a distinct, round patch.
  • #f43f5e 30%, #18181b 30%

    hard edge

    Two colours at the same position draw a circle with a sharp edge instead of a glow.
  • two patches of light

    several layers

    Two gradients with transparent ends and a colour underneath. This is how soft, coloured backgrounds are made.
  • repeating-radial-gradient()

    rings

    A pattern repeated from the centre outwards. Hard edges give concentric rings.

Syntax variants in practice

#

#7c3aed, #18181b

With no extra settings the gradient is an ellipse matched to the element and starts at its centre.
.demo {
  background: radial-gradient(#7c3aed, #18181b);
}

circle

The word circle forces a circle, regardless of the element’s proportions.
.demo {
  background:
    radial-gradient(circle, #7c3aed, #18181b);
}

circle at top left

After at you give the position of the centre. The light falls from the top left corner.
.demo {
  background: radial-gradient(
    circle at top left, #0ea5e9, #18181b);
}

circle closest-side

The gradient ends at the nearest edge of the element, so in a wide rectangle it creates a distinct, round patch.
.demo {
  background: radial-gradient(
    circle closest-side, #f59e0b, #18181b);
}

#f43f5e 30%, #18181b 30%

Two colours at the same position draw a circle with a sharp edge instead of a glow.
.demo {
  background: radial-gradient(circle,
    #f43f5e 30%, #18181b 30%);
}

two patches of light

Two gradients with transparent ends and a colour underneath. This is how soft, coloured backgrounds are made.
.demo {
  background:
    radial-gradient(at 20% 30%, #7c3aed, transparent 55%),
    radial-gradient(at 80% 70%, #0ea5e9, transparent 55%),
    #18181b;
}

repeating-radial-gradient()

A pattern repeated from the centre outwards. Hard edges give concentric rings.
.demo {
  background: repeating-radial-gradient(circle,
    #7c3aed 0 8px, #18181b 8px 16px);
}

More examples

#
A vignette on a photo
CSS
.photo {
  background:
    radial-gradient(ellipse, transparent 35%, rgb(0 0 0 / 0.85)),
    url("/collections/covers/programowanie-dla-dzieci.webp") center / cover;
}
Preview

The centre of the photo stays light and the edges darken. The vignette draws the eye to the centre of the frame.

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • For soft lights, make the last colour transparent and layer several gradients in a single background.
  • A circle of fixed size is written as circle 80px. With circle the size must be a length, and percentages are allowed only with ellipse.
  • Under the gradients, give a plain colour as the last layer, for example …, #111114. It fills the places where the gradients are transparent.

Related entries

#

Spotted a mistake or missing an example? Write to us.