CSS radial-gradient(): Syntax and Examples
Contents
radial-gradient() creates a gradient that spreads outward from a point, in a circle or an ellipse. Like all CSS gradients it’s an image, so you use it with background or background-image:
background: radial-gradient(circle, #3b82f6, #1e3a8a);
Want to design one visually? The CSS gradient generator builds linear, radial and conic gradients and gives you the code.
Demo:
The syntax
radial-gradient( [shape] [size] [at position], color-stop, color-stop, ... )
Everything before the colors is optional. With no options you get an ellipse, centered, sized to reach the farthest corner.
Shape: circle or ellipse
ellipse (the default) stretches to the box’s proportions, so in a wide box the gradient is wide. circle stays round whatever the box’s shape.
.a { background: radial-gradient(ellipse, #60a5fa, #1e3a8a); }
.b { background: radial-gradient(circle, #60a5fa, #1e3a8a); }
Size: how far the gradient reaches
The size decides where the last color stop sits. Four keywords measure from the center to the box’s edges: closest-side, closest-corner, farthest-side and farthest-corner (the default). You can also give exact lengths: one for a circle’s radius, two for an ellipse.
.a { background: radial-gradient(circle closest-side, #60a5fa, #1e3a8a); }
.b { background: radial-gradient(circle 80px, #60a5fa, #1e3a8a); }
.c { background: radial-gradient(200px 80px, #60a5fa, #1e3a8a); } /* ellipse */
Position: at ...
Move the center with at followed by keywords, percentages or lengths, just like background-position.
.a { background: radial-gradient(circle at top right, #93c5fd, #1e3a8a); }
.b { background: radial-gradient(circle at 30% 70%, #93c5fd, #1e3a8a); }
.c { background: radial-gradient(circle at 0 0, #93c5fd, #1e3a8a); }
Color stops and hard edges
Each color can have a position. When two stops share a position, the change is instant instead of gradual, which is how you draw solid circles and rings with a gradient.
/* Soft: blends over the whole radius */
background: radial-gradient(circle, #1d4ed8, #bfdbfe);
/* Hard edge: a solid circle */
background: radial-gradient(circle, #1d4ed8 50%, #bfdbfe 50%);
/* Avoid jagged edges: leave half a pixel to blend */
background: radial-gradient(circle, #1d4ed8 50%, #bfdbfe calc(50% + 0.5px));
Practical examples
Glow behind content
Fade a color to transparent and layer it over a solid background. Popular on dark hero sections.
.hero {
background:
radial-gradient(circle at 50% 0%, rgb(59 130 246 / 0.5), transparent 60%),
#0f172a;
}
Dot grid pattern
A tiny hard-edged circle, repeated with background-size. Change the size to change the spacing.
.dots {
background-color: #fff;
background-image: radial-gradient(#cbd5e1 1px, transparent 1.5px);
background-size: 20px 20px;
}
Vignette over an image
Darken the edges of a photo by layering a gradient on top of it. The first background in the list is drawn on top.
.photo {
background:
radial-gradient(ellipse, transparent 50%, rgb(0 0 0 / 0.6)),
url("photo.jpg") center / cover;
}
Repeating rings
repeating-radial-gradient() repeats the color stops outward forever. Good for targets, ripples and retro backgrounds. Its linear sibling, repeating-linear-gradient(), makes striped backgrounds.
.rings {
background: repeating-radial-gradient(
circle,
#1d4ed8 0 10px,
#3b82f6 10px 20px
);
}
Radial vs linear vs conic
linear-gradient(): colors change along a straight line. Great for backgrounds, overlays, gradient text and gradient borders.radial-gradient(): colors spread outward from a point. Glows, spotlights, dots, vignettes.conic-gradient(): colors rotate around a point, like a color wheel. Pie charts and spinners.
All three can be layered in one background, separated by commas. For shadows rather than backgrounds, the box shadow generator is often the simpler tool.
FAQ
How do I make a circular gradient in CSS?
background: radial-gradient(circle, #60a5fa, #1e3a8a);. Without circle, the gradient is an ellipse that follows the shape of the box.
How do I change where a radial gradient starts?
Add at and a position: radial-gradient(circle at top left, ...) or radial-gradient(circle at 20% 80%, ...).
Why does my radial gradient look jagged?
Hard color stops at the exact same position get no anti-aliasing. Leave about half a pixel between them: #1d4ed8 50%, #bfdbfe calc(50% + 0.5px).
Can I animate a radial gradient?
Not directly; gradients aren’t animatable images. Animate background-position or background-size, or register a custom property with @property and animate that inside the gradient.
Related: CSS gradient generator, free CSS generators, CSS ::before and ::after and CSS tips.