SVG Circle

What You’ll Learn
How to create and customize SVG circles in HTML using the <circle> element. Circles are one of the fundamental shapes in Scalable Vector Graphics and form the basis for icons, charts, badges, and decorative elements on the web.
You’ll see the syntax, the three core attributes (cx, cy, r), styling with fill, stroke, and stroke-width, plus a complete HTML example, a live preview, and best practices for clean, accessible SVG markup.
⚡ Quick Reference — SVG Circle Attributes
numberx-coordinate of the center
numbery-coordinate of the center
numberRadius of the circle
colorInside fill colour
colorOutline colour
numberOutline thickness in pixels
<svg>
<circle cx="x-coordinate" cy="y-coordinate" r="radius" />
</svg>Complete HTML Example
This example draws an orange circle with a black border, centered at (100, 100) with a radius of 50 units inside a 200×200 SVG canvas:
<!DOCTYPE html>
<html>
<body>
<svg width="200" height="200">
<circle cx="100" cy="100" r="50" fill="orange" stroke="black" stroke-width="2" />
</svg>
</body>
</html>👀 Live Preview — Circle Variations
See how different attribute combinations change the appearance of an SVG circle:
🧠 How It Works
Open an <svg> canvas
Wrap your shape in an <svg> element. Give it a width and height (or a viewBox) so the browser knows how big the drawing area is.
Set the center with cx and cy
cx is the horizontal position of the centre and cy is the vertical position. The origin (0, 0) is the top-left corner of the SVG.
Choose a radius (r)
r defines the radius in user units. Make sure cx + r and cy + r stay inside the SVG bounds, otherwise the circle gets clipped.
Style with fill & stroke
Use fill for the inside colour, stroke for the outline, and stroke-width for the outline thickness. Set fill="none" for an outline-only circle.
A crisp, scalable circle
SVG circles render at any resolution without blurring because they are vector shapes. The browser draws them in real time using the centre, radius, and fill/stroke values.
Use Cases
SVG circles show up almost everywhere on the modern web. Here are the most common use cases:
Profile bubbles, status dots, and round icon backgrounds.
Pie segments, donut charts, scatter plot points, and bubble charts.
Animated stroke-dash circles for loading and progress UI.
Circular badges, notification dots, and toggle indicators.
Brand marks built from one or more layered circles.
Geometry lessons, physics diagrams, and interactive demos.
Location pins, heat-map dots, and clustered map markers.
💡 Best Practices
Do
- Use a
viewBoxon the parent<svg>for responsive scaling - Add
role="img"andaria-labelfor accessibility - Pick stroke widths that align with whole pixels (1, 2, 3…) to stay crisp
- Style with CSS variables for easy theming (light / dark)
- Use
fill="currentColor"to inherit the parent text colour
Don’t
- Forget that the origin
(0, 0)is the top-left corner - Place the circle so that
cx + roverflows the SVG width - Use
fill="none"without setting astroke— nothing renders - Hard-code pixel sizes when you need a responsive icon
- Skip the
rattribute — it defaults to0(invisible)
Key Takeaways
Three attributes define every SVG circle
cx cy rStyle with fill, stroke, and stroke-width
SVG is vector-based — circles stay sharp at any size or resolution
The origin (0, 0) is the top-left of the SVG canvas
Add a viewBox for responsive, scalable graphics
❓ Frequently Asked Questions
<circle> element inside an <svg>. Set cx and cy for the centre, r for the radius, and optionally fill, stroke, and stroke-width for styling. Example: <circle cx="100" cy="100" r="50" fill="orange" stroke="black" stroke-width="2" />.cx is the x-coordinate of the circle’s centre, cy is the y-coordinate of the centre, and r is the radius. All three values default to 0 if you omit them.viewBox attribute to the parent <svg> instead of fixed width and height, then size the SVG with CSS. The circle will scale proportionally because SVG is vector-based.fill, stroke, and stroke-width can be set directly on the element or via CSS selectors. CSS lets you add hover, focus, transitions, and animations.r is 0 or missing, the circle is outside the viewBox or container size, fill is set to none with no stroke, or the parent <svg> has zero width or height.Master Every SVG Shape!
Continue with ellipses, lines, polygons, and paths to draw any 2D vector graphic in HTML.
9 people found this page helpful
