π What Is radial-gradient()?
The radial-gradient() function creates a gradient that radiates outward from a center point, forming circles or ellipses. It is perfect for spotlight effects, soft backgrounds, UI highlights, 3D illusions, and decorative patterns.
Note
β Supports positioned centers
β Accepts multiple color stops
β Can be combined with images
π¦ Syntax
Basic Syntax
radial-gradient(shape size at position, color-stop1, color-stop2, ...);Parts of the syntax (all optional except colors):
- shape: circle or ellipse
- size: closest-side, farthest-side, closest-corner, farthest-corner
- position: center, top left, 20% 80% etc.
π 1. Basic Circle Gradient
Simple circle
background: radial-gradient(circle, red, blue);A smooth transition from red at the center β blue at the edges.
π 2. Basic Ellipse Gradient (Default)
Ellipse gradient
background: radial-gradient(ellipse, orange, purple);Ellipses are the default shape; the gradient scales to fit the element.
π 3. Positioning the Gradient Center
Top-left gradient
background: radial-gradient(circle at top left, red, blue);You can place the gradient center anywhere:
- at center
- at top
- at bottom right
- at 20% 70%
π 4. Controlling the Gradient Size
Size keywords
background: radial-gradient(circle closest-side, red, blue);| Size | Description |
|---|---|
| closest-side | Stops at the nearest side |
| farthest-side | Stops at the farthest side |
| closest-corner | Stops at nearest corner |
| farthest-corner | Stops at farthest corner (default) |
π 5. Multiple Color Stops
Multi-stop
background: radial-gradient(circle, red 0%, yellow 40%, green 80%, blue 100%);Each stop defines a color and where it appears.
π 6. Hard Stops (Sharp Transition)
Hard stops
background: radial-gradient(circle, red 0 40%, blue 40% 100%);Creates instant transitions β useful for simple rings or spotlight edges.
π 7. Transparent Radial Gradients
Transparent glow
background: radial-gradient(
circle,
rgba(255,255,255,0.8),
rgba(255,255,255,0)
);Great for glow effects and overlays.
π 8. Using Radial Gradient for Shadows
Glow shadow
box-shadow: 0 0 40px 20px radial-gradient(circle, rgba(0,0,0,0.3), transparent);Creates soft, realistic shadows and glows.
π 9. Repeating Radial Gradients
Polka dots
background: repeating-radial-gradient(
circle,
black 0,
black 5px,
white 5px,
white 20px
);Creates patterns like polka dots or ripples.
π 10. Combining Radial Gradients With Images
Gradient overlay
background:
radial-gradient(circle at center, rgba(0,0,0,0.5), transparent),
url('photo.jpg');Common for vignette or spotlight effects.
π 11. Creating a Vignette Effect
Vignette
background: radial-gradient(
circle farthest-corner,
transparent 60%,
rgba(0,0,0,0.7)
);Dramatic image framing for UI banners.
π§ͺ Real-World Examples
1οΈβ£ Soft Background for Cards
Soft background
.card {
background: radial-gradient(circle at top, #ffe0e0, #ff8a8a);
}2οΈβ£ Spotlight Effect
Spotlight
.spotlight {
background: radial-gradient(circle at 50% 30%, white, rgba(0,0,0,0.8));
}3οΈβ£ Button Glow
Glow button
.btn {
background: radial-gradient(circle at center, #ffffffaa, #00000000),
linear-gradient(to right, #4facfe, #00f2fe);
}β οΈ Common Mistakes
- β Forgetting that radial gradients scale to element size
- β Using too many color stops β muddy appearance
- β Expecting linear behavior (radial spreads outward)
- β Misplacing gradient center (e.g., at 100% triggers overflow)
Note
π₯ Summary
radial-gradient() is a powerful tool for creating circular or elliptical gradients with smooth or sharp transitions. It's ideal for glowing effects, backgrounds, overlays, shadows, highlights, and decorative UI visuals.
Learn more βMDN Docs π