🌐 CSS radial-gradient() β€” Complete Tutorial

🌈 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.

>>β€œWhile linear gradients move in a straight line, radial gradients expand outward from a center point β€” like ripples in water.”

Note

βœ” Supports circular & elliptical shapes
βœ” 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);
SizeDescription
closest-sideStops at the nearest side
farthest-sideStops at the farthest side
closest-cornerStops at nearest corner
farthest-cornerStops 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

For predictable results, always define **shape**, **position**, and **color stops** clearly.

πŸ”₯ 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.

>>β€œRadial gradients give depth, focus, and atmosphere to modern UI designs.”

Learn more β†’MDN Docs πŸ“˜