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:
-
cxandcyThe attribute defines the coordinates of the ellipse's center point, 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 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
"
/>
svgTry it »
Click to view:View SVG File.
Code analysis:
- 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 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
"
/>
svgTry 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
"
/>
svgTry it »
Click to view:View SVG File.