Chapter 6: SVG circle

SVG Circle means using the <circle> tag inside SVG code to draw a perfect circle (or filled dot, ring, button shape, etc.). It’s one of the easiest basic shapes in SVG — after rectangle, this is usually the second thing everyone learns because circles are everywhere: icons (like user profile pic), buttons, progress rings, loaders, charts (scatter plots), eyes in emojis, etc.

1. Why <circle> is Special in SVG

  • It’s perfectly round — no need to calculate curves like with <path>
  • Vector = zoom forever, still sharp (no pixel blur like PNG)
  • Super simple: only 3 main attributes needed to start
  • Can be styled, animated, filled, outlined — very flexible for web design

2. Basic Syntax of <circle>

XML
  • Self-closing tag (ends with />)
  • Must live inside <svg>…</svg>
  • cx, cy, r are in user units (like pixels if viewBox matches)
  • r is required — no radius = no circle!
  • cx and cy default to 0 if missing (circle starts at top-left)

3. Your First SVG Circle (Copy-Paste Right Now!)

Make a file circle.html:

HTML

What you see: A big red circle perfectly centered.

Code explanation (like blackboard):

  • cx=”100″ → center horizontally at 100 units (middle of 200 width)
  • cy=”100″ → center vertically at 100 units
  • r=”80″ → radius 80 → full diameter 160 units (fits nicely inside 200×200)
  • fill=”red” → inside color (default black if missing)
  • No stroke → no border

Zoom browser tab — still perfect!

4. All Important Attributes (Full List Like Notes)

Attribute Meaning Required? Default Example Notes
cx X-coordinate of center No 0 50, 120, 50% Horizontal from left
cy Y-coordinate of center No 0 80, 150 Vertical from top
r Radius (distance from center to edge) Yes 40, 25, 50px If ≤0 → invisible
fill Color inside No black blue, #ff0000, none none = transparent
stroke Outline/border color No none black, #333 No border if missing
stroke-width Border thickness No 1 5, 10, 3px In user units
opacity Whole circle transparency No 1 0.6, 0.8 0 = invisible
stroke-dasharray Dashed border pattern No “10 5” Dash 10, gap 5

5. More Fun & Useful Examples (Try These!)

Example 1: Circle with Border (Ring Style)

XML

→ Hollow purple ring (great for progress indicators!)

Example 2: Smiley Face Using Multiple Circles

HTML

Example 3: Gradient Fill Circle (Modern Look)

XML

→ Nice shiny blue ball!

Example 4: Hover Effect with CSS

HTML

Hover → grows bigger and changes color!

6. Teacher’s Tips (Hyderabad Student Special 😄)

  • Always use viewBox=”0 0 W H” → makes circle responsive (scales on mobile)
  • For charts (D3.js, charts.js) — circles represent data points
  • Progress rings? Use two circles: background gray + animated stroke-dasharray
  • Common mistake: Forget r → nothing shows! Or wrong cx/cy → circle off-screen
  • Tools: Figma/Inkscape export circle as SVG → copy code to HTML

Understood the circle fully? Want next: animated spinning circle? Progress ring example? Or circle with text inside (like percentage badge)? Or compare with <ellipse>? Just say — we keep building! 🚀

You may also like...

Leave a Reply

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