Basic Shape
Let's learn how to draw basic shapes.
SVG attributes
pathLength
Changes how the path length is computed. Instead of using the actual computed length, force the computer to use this number.
| LIVE PREVIEW
SVG elements
<circle>
cx— center x (specify length or percentage)cy— center y (specify length or percentage)r— radius (specify length or percentage)pathLength— when drawing the stroke, assume the circumference of the circle is this number (this won't change the size of the circle)
| LIVE PREVIEW
<ellipse>
cx— center x (specify length or percentage)cy— center y (specify length or percentage)rx— radius in the x-axis (specify length or percentage)rx— radius in the y-axis (specify length or percentage)pathLength— when drawing the stroke, assume the circumference of the ellipse is this number (this won't change the size of the ellipse)
| LIVE PREVIEW
<rect>
x— top-left x coordinate (specify length or percentage)y— top-left y coordinate (specify length or percentage)width— width (specify length or percentage)height— height (specify length or percentage)rx— horizontal corner radius of the rectangle (specify length or percentage, takes the value ofryif it's specified)ry— horizontal corner radius of the rectangle (specify length or percentage, takes the value ofrxif it's specified)pathLength— when drawing the stroke, assume the perimeter of the rectangle is this number (this won't change the size of the rectangle)
| LIVE PREVIEW
<polygon>
points— space-separatedx,ycoordinates of the polygon (only accepts numbers for both x and y)pathLength— when drawing the stroke, assume the perimeter of the polygon is this number (this won't change the size of the polygon)
| LIVE PREVIEW
<line>
x1— starting x coordinate (specify length or percentage)y1— starting y coordinate (specify length or percentage)x2— ending x coordinate (specify length or percentage)y2— ending y coordinate (specify length or percentage)pathLength— when drawing the stroke, assume the length of the line is this number
| LIVE PREVIEW
<polyline>
Creates an open shape (unlike <polygon>).
points— space-separatedx,ycoordinates of the polyline (only accepts numbers for both x and y)pathLength— when drawing the stroke, assume the length of the polyline is this number
| LIVE PREVIEW
References
- pathLength (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/pathLength
- <circle> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/circle
- <ellipse> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/ellipse
- <rect> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/rect
- <polygon> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/polygon
- <line> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/line
- <polyline> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/polyline