HTML SVG <circle>

Beginner
8 min read
Updated: Nov 2026
5 examples
Live preview

Definition and Usage

The SVG <circle> element draws a circle from a center point (cx, cy) and a radius (r). Place it inside an <svg>.

Style with fill, stroke, and stroke-width (attributes or CSS). For ovals with unequal axes, use <ellipse> instead.

Baseline · Widely available.

<circle> is a stable SVG basic shape across modern browsers since about July 2015.

SVG2 · Geometry as CSS.

In SVG2, cx, cy, and r are also geometry properties — you can set them as CSS where supported.

Zero radius hides the circle.

If r is missing, 0, or negative, nothing is drawn. Always set a positive radius.

Syntax

circle.html
<svg width="200" height="200" viewBox="0 0 200 200"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Example circle">
  <circle cx="100" cy="100" r="60"
          fill="#2563eb" stroke="#0f172a" stroke-width="4" />
</svg>

Self-closing <circle /> is fine in HTML. Keep meaningful aria-label (or title) when the graphic matters.

Attributes

Core <circle> attributes:

AttributeDescriptionTry it
cxCenter X (default 0)Try it
cyCenter Y (default 0)Try it
rRadius; ≤ 0 disables renderingTry it
fill / strokeInterior and outline colorsTry it
stroke-widthOutline thicknessTry it
pathLengthOptional path length for dash mathTry it

Global Attributes

The <circle> tag also supports the Global Attributes in HTML (for example id, class, lang, title) when used in an HTML document.

Live Preview

Change the radius and toggle stroke. The center stays fixed at (100, 100).

50

viewBox keeps the graphic scalable while you edit r.

SVG

cx="100" cy="100" r="50"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic Filled Circle

Set center, radius, fill, and a light stroke.

HTML
<svg width="200" height="200" viewBox="0 0 200 200"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Blue filled circle">
  <circle cx="100" cy="100" r="60"
          fill="#2563eb" stroke="#0f172a" stroke-width="3" />
</svg>
Try It Yourself

How It Works

  1. Create an <svg> with a matching viewBox.
  2. Set cx / cy to the center.
  3. Set r to the radius.
  4. Add fill and stroke for color and outline.

Example 2 — Stroke Only

Use fill="none" for a ring.

HTML
<svg width="200" height="200" viewBox="0 0 200 200"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Outlined circle ring">
  <circle cx="100" cy="100" r="55"
          fill="none" stroke="#16a34a" stroke-width="8" />
</svg>
Try It Yourself

How It Works

  1. fill="none" leaves the interior empty.
  2. stroke draws the circumference.
  3. stroke-width sets thickness.
  4. Same cx, cy, r as a filled circle.

Example 3 — Multiple Circles

Several circles share one SVG coordinate system.

HTML
<svg width="280" height="140" viewBox="0 0 280 140"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Three colored circles">
  <circle cx="60" cy="70" r="40" fill="#2563eb" />
  <circle cx="140" cy="70" r="40" fill="#7c3aed" />
  <circle cx="220" cy="70" r="40" fill="#ea580c" />
</svg>
Try It Yourself

How It Works

  1. One <svg> holds every shape.
  2. Change cx to space circles horizontally.
  3. Keep cy and r equal for a neat row.
  4. Later shapes paint on top if they overlap.

Example 4 — Overlap with Opacity

Use fill-opacity to see overlapping areas.

HTML
<svg width="240" height="160" viewBox="0 0 240 160"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Overlapping semi-transparent circles">
  <circle cx="95" cy="80" r="55" fill="#2563eb" fill-opacity="0.55" />
  <circle cx="145" cy="80" r="55" fill="#facc15" fill-opacity="0.55" />
</svg>
Try It Yourself

How It Works

  1. Two centers sit close so the disks overlap.
  2. fill-opacity="0.55" lets both colors show through.
  3. You can also use opacity on the whole element (fill + stroke).
  4. Useful for Venn-style diagrams and soft badges.

Example 5 — Dashed Stroke

Combine stroke-dasharray with a stroked circle.

HTML
<svg width="200" height="200" viewBox="0 0 200 200"
     xmlns="http://www.w3.org/2000/svg"
     role="img" aria-label="Dashed circle outline">
  <circle cx="100" cy="100" r="60"
          fill="none" stroke="#7c3aed" stroke-width="6"
          stroke-dasharray="12 8" />
</svg>
Try It Yourself

How It Works

  1. Stroke-only circle as in example 2.
  2. stroke-dasharray="12 8" means 12 on, 8 off.
  3. Optional pathLength can normalize dash math for animation.
  4. See also the SVG stroke page for more line styles.

Edge Cases & Pitfalls

Most missing-circle bugs are radius, viewport, or fill/stroke settings.

radius

r must be positive

Default r is 0. Zero or negative values disable rendering.

viewBox

Stay inside the viewBox

If the circle sits outside viewBox / SVG size, it is clipped or invisible. Size the SVG to fit cx ± r and cy ± r.

style

fill none needs a stroke

With fill="none" and no stroke, you see nothing. Set at least one visible paint.

units

User units, not CSS px alone

Coordinates live in the SVG user space. Prefer viewBox + CSS sizing over only hard-coded pixel layouts.

Browser Support

The SVG <circle> element is supported in every modern browser.

✓ Baseline · Widely available

SVG <circle>

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support circle geometry and presentation attributes. Internet Explorer 9+ supports basic SVG circles.

98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer 9+
Supported
<circle> Widely supported

Bottom line: Safe for production icons, charts, and UI marks. Prefer attributes for teaching; CSS geometry properties are fine in modern browsers.

Key Takeaways

  • Geometry: cx, cy, positive r.
  • Paint: fill, stroke, stroke-width.
  • Scale: parent viewBox + CSS size.
  • Oval? Use <ellipse> with rx/ry.

One line: center + radius + paint inside an <svg>.

Default CSS Settings

SVG shapes use presentation defaults more than a browser CSS rule sheet. Typical initial paint:

defaults.css
/* Conceptual SVG defaults */
circle {
  fill: black;
  stroke: none;
  stroke-width: 1;
}

Set fill / stroke explicitly in examples so results stay predictable across contexts.

Frequently Asked Questions

Put a <circle> inside an <svg>. Set cx and cy for the center, r for the radius, then style with fill and/or stroke.
cx and cy are the center coordinates. r is the radius. Defaults are 0. If r is 0 or less, the circle is not rendered.
circle uses one radius (r). ellipse uses rx and ry. Prefer circle when both axes are equal.
Common causes: r is 0, the shape is outside the viewBox, fill is none with no stroke, or the SVG has zero width/height.
Yes. Use presentation attributes or CSS (including SVG2 geometry properties cx, cy, and r as CSS where supported).
Give the parent svg a viewBox, then size the svg with CSS. The vector circle scales cleanly.

Next: SVG Ellipse

Learn rx and ry for ovals and stretched rings.

SVG Ellipse →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful