radial-gradient()
Creates a colour transition radiating outwards from a point, along a circle or an ellipse. Good for glows, vignettes, and soft lights.
Example
#.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;
}<div class="card" style="padding: 22px; border: 1px solid #27272a; border-radius: 16px;">
<strong style="font-size: 18px;">World 2: Journey into Space</strong>
<p style="margin: 4px 0 0; color: #a1a1aa;">16 modules on JavaScript and React.</p>
</div>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
#radial-gradient([<shape> <size>]? [at <position>]?, <color> <position>?, <color> <position>?, …)Syntax variants
#ellipse from the centre
With no extra settings the gradient is an ellipse matched to the element and starts at its centre.circle
The wordcircleforces a circle, regardless of the element’s proportions.centre in a corner
Afteratyou give the position of the centre. The light falls from the top left corner.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.hard edge
Two colours at the same position draw a circle with a sharp edge instead of a glow.several layers
Two gradients with transparent ends and a colour underneath. This is how soft, coloured backgrounds are made.rings
A pattern repeated from the centre outwards. Hard edges give concentric rings.
Syntax variants in practice
##7c3aed, #18181b
.demo {
background: radial-gradient(#7c3aed, #18181b);
}circle
circle forces a circle, regardless of the element’s proportions..demo {
background:
radial-gradient(circle, #7c3aed, #18181b);
}circle at top left
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
.demo {
background: radial-gradient(
circle closest-side, #f59e0b, #18181b);
}#f43f5e 30%, #18181b 30%
.demo {
background: radial-gradient(circle,
#f43f5e 30%, #18181b 30%);
}two patches of light
.demo {
background:
radial-gradient(at 20% 30%, #7c3aed, transparent 55%),
radial-gradient(at 80% 70%, #0ea5e9, transparent 55%),
#18181b;
}repeating-radial-gradient()
.demo {
background: repeating-radial-gradient(circle,
#7c3aed 0 8px, #18181b 8px 16px);
}More examples
#.photo {
background:
radial-gradient(ellipse, transparent 35%, rgb(0 0 0 / 0.85)),
url("/collections/covers/programowanie-dla-dzieci.webp") center / cover;
}<div class="photo" style="height: 200px; border-radius: 14px;"></div>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
transparentand layer several gradients in a singlebackground. - A circle of fixed size is written as
circle 80px. Withcirclethe size must be a length, and percentages are allowed only withellipse. - 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
#- linear-gradient()Creates a smooth colour transition along a straight line. It is used as an image, most often in background or background-image.
- conic-gradient()Creates a colour transition around a point, like a clock hand. It draws pie charts, colour wheels, and rotating borders.
- background-imageSets an image or gradient as an element’s background.
- backgroundA shorthand that sets all background properties in one declaration.
- mask-imageUses an image or gradient as a transparency mask for an element.
Spotted a mistake or missing an example? Write to us.