SVG Ellipse<ellipse>

In SVG, the<ellipse>element is used to draw ellipses, and it is one of the commonly used basic shapes in SVG.

Using the<ellipse>element, you can create elliptical shapes, and control the position, size, and style of the ellipse by setting attributes.

Basic Syntax

<ellipse
  cx="x-coordinate"      <!-- 椭圆中心点的 x 坐标 -->
  cy="y-coordinate"      <!-- 椭圆中心点的 y 坐标 -->
  rx="x-radius"          <!-- 椭圆水平轴的半径 -->
  ry="y-radius"          <!-- 椭圆垂直轴的半径 -->
  fill="fill-color"      <!-- 椭圆的填充颜色 -->
  stroke="stroke-color"  <!-- 椭圆的描边颜色 -->
  stroke-width="width"   <!-- 椭圆的描边宽度 -->
/>

Attribute explanation:

  • cxandcyThe attribute defines the center point coordinates of the ellipse, i.e. the center position of the ellipse.

  • rxThe attribute defines the radius of the ellipse's horizontal axis (x-axis).

  • ryThe attribute defines the radius of the ellipse's vertical axis (y-axis).

  • fillThe attribute defines the fill color of the ellipse.

  • strokeThe attribute defines the stroke color of the ellipse.

  • stroke-widthThe attribute defines the stroke width of the ellipse.

The following code draws an ellipse with a blue fill, black stroke, horizontal axis radius of 80 pixels, vertical axis radius of 50 pixels, and center point coordinates of (100, 100).

<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
  <ellipse cx="100" cy="100" rx="80" ry="50" fill="blue" stroke="black" stroke-width="2" />
</svg>

Example 1

An ellipse is very similar to a circle, except that the ellipse has different x and y radii, while a circle has the same x and y radii.

The following is the SVG code:

Example

<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <ellipse cx="300" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2"/> </svg>

Try it Yourself »

Click to view:View SVG file。

Code explanation:

  • The CX attribute defines the x coordinate of the ellipse's center.
  • The CY attribute defines the y coordinate of the ellipse's center.
  • The RX attribute defines the horizontal radius.
  • The RY attribute defines the vertical radius.

Example 2

The following example creates three ellipses stacked on top of each other.

The following is the SVG code:

Example

<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <ellipse cx="240" cy="100" rx="220" ry="30" style="fill:purple"/> <ellipse cx="220" cy="70" rx="190" ry="20" style="fill:lime"/> <ellipse cx="210" cy="45" rx="170" ry="15" style="fill:yellow"/> </svg>

Try it Yourself »

Click to view:View SVG file。


Example 3

The following example combines two ellipses (one yellow and one white).

The following is the SVG code:

Example

<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <ellipse cx="240" cy="50" rx="220" ry="30" style="fill:yellow"/> <ellipse cx="220" cy="50" rx="190" ry="20" style="fill:white"/> </svg>

Try it Yourself »

Click to view:View SVG file。


Other Extensions