SVG Shapes (Circles, Rectangles, Lines)
The simplest shapes in SVG are the rectangle, circle, ellipse and line. Every shape has their own set of attributes for defining their position, geometry and size. The actual presentation of the shape is handled by attributes that are common for all shapes. For example, the attribute fill used below fills in the shape with the specified color. Filling and stroking shapes is covered in this section. All the presentation attributes are shown in the appendix with links to the relevant tutorial section.
On this page: Rectangle, Circle, Ellipse & Line
Legend
BOLD means the attribute is required.
Green means the attribute is optional.
Italics denotes a presentation attribute of the shape like fill which is both optional and shared with other SVG elements.
The 'rect' Element
Attribute |
Explanation | Example |
x |
The x-axis top-left corner of the rectangle | |
y |
The y-axis top-left corner of the rectangle | |
rx |
For rounded rectangles. x-axis radius used to round the element (0 default) | |
ry |
For rounded rectangles. y-axis radius used to round the element (0 default) | |
width |
The width of the rectangle | |
height |
The height of the rectangle | |
Presentation Attributes |
The 'circle' Element
Attribute |
Explanation | Example |
cx |
The x-axis center of the circle | |
cy |
The y-axis center of the circle | |
r |
The circle's radius | |
Presentation Attributes |
The 'ellipse' Element
Attribute |
Explanation | Example |
cx |
The x-axis center of the ellipse | |
cy |
The y-axis center of the ellipse | |
rx |
The length of the ellipse's radius along the x-axis | |
ry |
The length of the ellipse's radius along the y-axis | |
Presentation Attributes |
In case you're wondering, a SVG circle is just shorthand for an ellipse with equal x-axis and y-axis radii.
The 'line' Element
Attribute |
Explanation | Example |
x1, y1 |
The start point of the line | |
x2, y2 |
The end point of the line | |
Presentation Attributes |
Next are polylines and polygons which allow the creation of open or closed arbitrary shapes that are built using connected lines.