Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

SVG Ellipse

SVG Ellipse

In SVG, the The element is used to draw ellipses; it is one of the commonly used basic shapes in SVG.

Use The element can create elliptical shapes, and the ellipse's position, size, and style can be controlled by setting attributes.

Basic Syntax



  cy="y-coordinate"      

  rx="x-radius"          

  ry="y-radius"          

  fill="fill-color"      

  stroke="stroke-color"  

  stroke-width="width"   

/>

Attribute Analysis:

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



  



Example 1

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

Below 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 »

Click to view:View SVG File.

Code analysis:

Example 2

The following example creates three stacked ellipses.

Below 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 »

Click to view:View SVG File.


Example 3

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

Below 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 »

Click to view:View SVG File.