Lesson 4
Objective: Learn to draw, position and style an ellipse.
<ellipse cx="0" cy="0" rx="40" ry="80"></ellipse>
<ellipse> ... </ellipse> The full ellipse element with open and closing tags.
<ellipse /> Because this does not contain any content it can also be used as a self-closing element.
The ellipse has four layout attributes you must know and remember:
cx Ellipse center position on the x-axis
cy Ellipse center position on the y-axis
rx The x radius of the ellipse (left and right radius)
ry The y radius of the ellipse (up and down radius)
This lesson introduces new style properties:
fill-opacity="0.5" Makes the object fill transparent. The value can be any number between 0 and 1. 0 is fully transparent, 1 is no transparency.
stroke-opacity="0.7" Makes the object strock transparent using the same 0-1 value system as above.
This first example has a larger ry value (vertical radius) making the ellipse vertical. The ry radius is set to 190px giving a total diameter of 380px. The viewBox is 400px tall and the stroke-width adds 5px to the height (2.5px top and bottom). If you change the value of ry to 200px you will see the ellipse is clipped top and bottom.
<ellipse cx="200" cy="200" rx="100" ry="190" stroke="black" stroke-width="5" fill="none"> </ellipse>
This second example has a larger rx value (horizontal radius) making the ellipse horizontal.
<ellipse cx="200" cy="200" rx="190" ry="100" stroke="red" stroke-width="5" fill="none"> </ellipse>
Here is the example SVG for those who are too lazy to type the SVG. View SVG Markup
Here are our standard SVG Cheatsheets you can download, print out and have ready when needed. There is also a text file containing annotated quickstarts for all major shapes and techniques.
SVG Editor. Access a full SVG Editor online at any time.