CSS
π― What is radial-gradient()?
radial-gradient() creates a gradient that starts from the center and expands outward in a circular or elliptical shape.
It is commonly used for:
- spotlight effects
- glowing backgrounds
- circular lighting
- soft color transitions
- modern UI effects
π§© Simple Definition
radial-gradient() = creates a circular or elliptical color transition
π‘ Basic Syntax
background: radial-gradient(
shape size at position,
color1,
color2,
...
);
π§ Parameters
radial-gradient() has four main parts:
- 1. Shape
- 2. Size
- 3. Position
- 4. Colors
πΉ 1. Shape
Defines the shape of the gradient.
| Value | Description |
|---|---|
| circle | Creates a perfect circle |
| ellipse | Creates an oval shape |
Example
background: radial-gradient(circle, red, blue);
π Creates a circular gradient.
πΉ 2. Size
Defines how far the gradient spreads.
| Value | Description |
|---|---|
| closest-side | Extends to nearest side |
| farthest-side | Extends to farthest side |
| closest-corner | Extends to nearest corner |
| farthest-corner | Extends to farthest corner |
π§ Most Common Value
farthest-corner
π Usually creates the smoothest full-area gradient.
πΉ 3. Position
Defines where the center of the gradient starts.
Common Positions
| Value | Description |
|---|---|
| at center | Starts from the center |
| at top left | Starts from top-left corner |
| at top right | Starts from top-right corner |
| at bottom left | Starts from bottom-left corner |
| at bottom right | Starts from bottom-right corner |
πΉ 4. Colors
Defines the colors used in the gradient.
The first color starts at the center, while the remaining colors spread outward.
π§© Basic Examples
πΉ 1. Simple Circular Gradient
background: radial-gradient(circle, red, yellow);
π Red begins in the center and smoothly transitions into yellow.
πΉ 2. Elliptical Gradient
background: radial-gradient(
ellipse,
lightblue,
blue
);
π Creates an oval-shaped transition from light blue to dark blue.
πΉ 3. Gradient Starting from a Corner
background: radial-gradient(
circle at top left,
pink,
purple
);
π The gradient starts in the top-left corner and spreads outward.
πΉ 4. Using Size Values
background: radial-gradient(
circle farthest-side at center,
orange,
black
);
π The gradient extends toward the farthest side of the element.
π¨ Practical Example
Spotlight Effect
.hero {
background: radial-gradient(
circle at center,
rgba(255,255,255,0.8),
rgba(0,0,0,0.9)
);
}
π Creates a spotlight-style lighting effect.
π¨ Combining with Other Backgrounds
Gradients can be layered with images.
Example
.hero {
background-image:
radial-gradient(
circle,
rgba(0,0,0,0.2),
rgba(0,0,0,0.8)
),
url("hero.jpg");
}
π Adds a dark radial overlay over the image.
β οΈ Important Notes
- radial-gradient() is treated as a background image.
- No actual image file is required.
- Gradients automatically scale responsively.
This makes them lightweight and performance-friendly.
βοΈ Difference Between linear-gradient() and radial-gradient()
| Property | Transition Style |
|---|---|
| linear-gradient() | Straight-line transition |
| radial-gradient() | Circular or elliptical transition |
π§ Common Use Cases
radial-gradient() is commonly used for:
- spotlight effects
- glowing buttons
- hero sections
- soft backgrounds
- artistic UI designs
- dark vignette overlays
π¨ Example: Glowing Button
button {
background: radial-gradient(
circle,
#00ffff,
#0066ff
);
}
π Creates a glowing modern button effect.
