Chapter 5: SVG circle

What is the <circle> element?

<circle> draws a perfect circle (or ellipse if you misuse it, but we normally use it for circles).

Unlike <rect> which starts from top-left corner, a circle is defined by its center point + radius.

That’s actually much more natural for round shapes!

The 3 absolutely essential attributes

Attribute Full name Meaning Required? Default Typical values
cx center x Horizontal position of the center No 0 number, %, etc.
cy center y Vertical position of the center No 0 number, %, etc.
r radius Distance from center to edge Yes number > 0

Remember SVG coordinate rules (very important):

  • (0,0) = top-left corner of the <svg>
  • x → increases right
  • y → increases down

Here are some clear diagrams showing how cx, cy, r work compared to rect and line:

How to Approach SVG Animations: A CSS Tutorial | Toptal®
toptal.com
HTML SVG course lesson | Uxcel
app.uxcel.com

Example 1 – Simplest possible circle (centered)

HTML

Result: Big orange circle nicely centered in a 220×220 box (110 is exactly half of 220 → perfect center)

SVG non-scaling circle and rectangle · Muffin Man
muffinman.io
SVG non-scaling circle and rectangle · Muffin Man

Example 2 – Circle with stroke (border) – very common

HTML

Example 3 – Many circles (dots, bubbles, loading indicator style)

HTML
SVG non-scaling circle and rectangle · Muffin Man
muffinman.io
SVG non-scaling circle and rectangle · Muffin Man

Example 4 – Circle as button / icon with hover (modern UI favorite)

HTML

Hover over it — feels like a real button!

Untitled
codepen.io
Let's talk SVG icons: Why and how to use (and create) them
ycode.com

Example 5 – Circle used for progress ring (very popular pattern)

(This one uses <circle> twice — background + progress arc. Full version often uses stroke-dasharray.)

HTML
Circle Progress Bar Using Html CSS and SVG | CSS Percentage Circle - YouTube
youtube.com
Circle Progress Bar Using Html CSS and SVG | CSS Percentage Circle – YouTube

Quick Cheat Sheet – <circle> vs <rect>

Goal Use <circle> when… Use <rect> when…
Perfect round shape Yes — natural choice No (needs big rx/ry)
Button, avatar, dot Yes Sometimes (rounded rect)
Progress ring / gauge Yes (with stroke-dasharray) No
Box / card background No Yes
Need exact center positioning Yes (cx/cy very convenient) No (have to calculate center)

Common beginner mistakes with <circle>

  • Forgetting r → nothing shows
  • Putting cx=0 cy=0 r=50 → circle is half-cut because center is at top-left
  • Thinking radius is diameter (no — radius = half the width)
  • Using very small stroke-width on huge radius → looks invisible

Ready to practice?

Try these mini-challenges:

  1. Make three overlapping circles with different colors and transparency (use opacity=”0.7″)
  2. Create a simple “target / bullseye” using 4 concentric circles
  3. Make a pulsing circle animation with CSS @keyframes (scale + opacity)

Paste your code here if you want — I’ll review it like we’re in class together 😊

Any part still fuzzy? Just point and ask — 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 *