Chapter 23: SVG Radial Gradients

SVG Radial Gradients

Imagine we’re sitting together again, code editor open, and I’m going to walk you through this very slowly and clearly, just like before — with plenty of copy-paste examples you can try immediately.

What is a Radial Gradient in SVG?

A radial gradient creates a smooth color transition that spreads outward (or inward) from a central point in a circular or elliptical pattern — like ripples in a pond, a spotlight, a glowing orb, or the shine on a metallic button.

  • Instead of changing color along a straight line (like linear gradients), it changes color radially — from the inside point outward.
  • The center is usually one color, and it smoothly blends to other colors as it moves toward the edges.
  • Very popular for: realistic buttons, orbs, glow effects, spotlights, metallic/reflective surfaces, radial backgrounds, 3D-looking spheres, badges, loaders, etc.

Where do we define it? → Inside <defs>

Just like linear gradients:

HTML

The <radialGradient> element – Core attributes

Attribute What it controls Common values Default Very important?
id Unique name to reference it “glow”, “orb”, “shine” ★★★★★
cx Horizontal center of the gradient circle (%) 50%, 30%, 0.5 50% ★★★★★
cy Vertical center of the gradient circle (%) 50%, 70% 50% ★★★★★
r Radius of the gradient circle (how far it spreads) 50%, 70%, 0.8 50% ★★★★★
fx, fy Focal point (where the “brightest” spot starts) 50%, 40% same as cx/cy ★★★★☆
gradientUnits Units for cx/cy/r/fx/fy “objectBoundingBox” or “userSpaceOnUse” objectBoundingBox ★★★★☆
spreadMethod What happens beyond radius pad / reflect / repeat pad ★★★☆☆

Most beginner-friendly & common setting (use this 90% of the time):

text

→ Gradient perfectly centered in the shape’s bounding box, spreading to the edges.

The <stop> elements — same as linear gradients

You control the colors the same way:

XML
  • offset=”0%” → color at the exact center (or focal point)
  • offset=”100%” → color at the outer edge (radius)

Example 1 – Simple centered radial gradient (classic orb/glow)

HTML

Result: White center fading smoothly to purple at the edges — looks like a soft glowing ball.

Here are some visual examples of simple radial gradients (imagine seeing these side by side):

  • White → light blue → deep blue
  • Yellow → orange → red (sun-like)
  • Silver → dark gray (metallic sphere)

Example 2 – Focal point offset (realistic shine/highlight)

HTML

→ fx/fy moved to top-left → creates a bright highlight spot (very common for buttons/icons).

Example 3 – Elliptical gradient (non-circular)

HTML

→ Because the shape is elliptical, the gradient stretches to match → creates oval glow.

Quick Cheat Sheet – Popular radial gradient styles

Style / Look cx/cy/fx/fy settings r value Typical stops sequence
Centered orb/glow 50% 50% 50% 50% 50–70% white → color → darker color
Button shine/highlight 30–40% 30–40% 30–40% 30–40% 60–80% white (high opacity) → base color → dark
Spotlight effect 50% 50% 50% 50% 40–60% bright → fade to transparent
Metallic/chrome 20% 20% 30% 30% 80–100% white → light gray → dark gray → black
Sunset/radial background 50% 30% 50% 50% 100% orange → purple → navy

Common beginner mistakes

  • Forget id → fill=”url(#wrongId)” shows nothing
  • r=”0.5″ instead of “50%” → tiny gradient (use % with objectBoundingBox)
  • No <stop> at 0% and 100% → gradient may look empty or wrong
  • gradientUnits=”userSpaceOnUse” without adjusting numbers → gradient doesn’t scale with shape
  • Too many stops too close → hard bands instead of smooth blend

Mini practice tasks

  1. Make a red-to-yellow sunset orb (centered radial gradient)
  2. Create a modern button look: blue circle + offset white highlight shine
  3. Try a metallic-looking sphere (silver gradient with offset focal point)

Paste your code here if you want feedback — I’ll review it like we’re pair-programming together 😊

Radial gradients are super powerful for giving flat shapes depth and realism — you now have both linear and radial in your toolbox!

Next we can cover repeating gradients, gradient on text/stroke, combining linear + radial, or animating gradients. Which direction sounds most fun to you? Or any part of radial gradients still fuzzy? Just say — we’ll zoom in until it’s crystal clear! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *