SVG Ellipse

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 1 Code Example
Basic Shape

What You’ll Learn

How to create and customize SVG ellipses in HTML using the <ellipse> element. Ellipses are like stretched circles and are useful for smooth, rounded visuals in icons, diagrams, and data visualisations.

You’ll learn the syntax, the four core attributes (cx, cy, rx, ry), styling with fill, stroke, and stroke-width, plus a complete example, live preview, and best practices.

⚡ Quick Reference — SVG Ellipse Attributes

cx number

x-coordinate of the centre

cy number

y-coordinate of the centre

rx number

Horizontal radius (x-axis)

ry number

Vertical radius (y-axis)

fill color

Inside fill colour

stroke color

Outline colour

stroke-width number

Outline thickness in pixels

Basic Syntax
<svg>
  <ellipse cx="center-x" cy="center-y" rx="x-radius" ry="y-radius" />
</svg>
1

Complete HTML Example

This example draws a green ellipse with a black border, centered at (100, 75) with radii rx=80 and ry=50 inside a 200×150 SVG canvas:

index.html
<!DOCTYPE html>
<html>
<body>

<svg width="200" height="150">
  <ellipse cx="100" cy="75" rx="80" ry="50" fill="green" stroke="black" stroke-width="2" />
</svg>

</body>
</html>
Try It Yourself

👀 Live Preview — Ellipse Variations

See how changing rx and ry (and styling) affects the shape:

Wide ellipse
Tall ellipse
Stroke only
Fill + stroke
Semi-transparent
Dashed border

🧠 How It Works

1

Create an SVG canvas

Place the ellipse inside an <svg>. Use width/height or a viewBox so the browser knows the coordinate space.

SVG canvas
2

Position the center (cx, cy)

cx and cy set the centre point. Like all SVG coordinates, (0, 0) is at the top-left.

Position
3

Set two radii (rx, ry)

rx defines half the width and ry defines half the height. If either value is missing or 0, the ellipse won’t render.

Size
4

Style with fill and stroke

Use fill for the inside and stroke/stroke-width for the outline. Set fill=\"none\" for outline-only ellipses.

Styling
=

A smooth, scalable ellipse

Ellipses are vector shapes, so they scale cleanly for icons, UI, and illustrations without pixelation.

Use Cases

Ellipses are especially useful when you need a circle-like shape that is stretched horizontally or vertically:

📊 Charts

Scatterplot points, bubbles, and decorative markers.

🎯 UI Pills

Tag and badge shapes (often used as backgrounds).

👀 Highlights

Glow and highlight layers behind icons/text.

🎨 Illustrations

Shadows, faces/eyes, and soft rounded elements.

⏳ Loading UI

Elliptical rings and progress frames.

🧮 Education

Geometry diagrams and coordinate-space demos.

💡 Best Practices

Do

  • Use a viewBox for responsive SVGs
  • Add role=\"img\" and aria-label for meaningful graphics
  • Keep rx and ry inside the canvas to avoid clipping
  • Use CSS classes for consistent styling across multiple ellipses
  • Prefer fill=\"none\" with a stroke for outline-only visuals

Don’t

  • Omit rx or ry — the ellipse becomes invisible
  • Assume an ellipse is a circle (a circle needs <circle> with r)
  • Place the center too close to the edge if you want the full ellipse visible
  • Use fixed pixel sizes when you need a responsive icon
  • Set fill=\"none\" without a stroke

Key Takeaways

1

An ellipse uses two radii

rx ry
2

Position it with cx and cy

3

Style it with fill and stroke settings

4

If rx or ry is 0, nothing renders

5

Use a viewBox for scalable graphics

❓ Frequently Asked Questions

Use <ellipse> inside an <svg>. Set cx and cy for the centre and rx/ry for the radii. Example: <ellipse cx="100" cy="75" rx="80" ry="50" />.
cx/cy set the centre point. rx is the horizontal radius and ry is the vertical radius. If either radius is missing or 0, the ellipse won’t render.
A <circle> uses one radius (r) and is always round. An <ellipse> uses two radii (rx, ry) so it can be stretched wider or taller.
Yes. Use fill, stroke, and stroke-width directly on the element or via CSS selectors. CSS also enables hover states and animations.
Check that rx and ry are not 0, your ellipse is within the SVG bounds (or viewBox), and you’re not using fill="none" without a stroke. Also ensure the parent <svg> has a visible size.

Level Up Your SVG Skills!

Next, explore filters to add shadows, blur, and pro-level effects to your shapes.

SVG Filters →

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.

7 people found this page helpful