SVG Notes: Line & Rect Reference

Just a guy who loves to write code and watch anime.
rect -> Rectangle
Basic Rectangle
<rect x="10" y="10" width="50" height="30" />
x, y= top-left corner positionwidth, height= dimensions
Rounded Corners
<rect x="10" y="10" width="50" height="30" rx="5" ry="5" />
rx= horizontal corner radiusry= vertical corner radiusIf only
rxspecified,rymatches automatically
With Styling
<rect x="10" y="10" width="50" height="30" fill="blue" stroke="red" stroke-width="2" />
line -> Line
Basic Line
<line x1="10" y1="10" x2="90" y2="50" />
x1, y1= start pointx2, y2= end pointImportant: Lines need
stroketo be visible (no area to fill)
Line End Styles
<line x1="10" y1="10" x2="90" y2="10" stroke="black" stroke-linecap="round" />
stroke-linecapoptions:"butt"(default) -> flat ends"round"-> rounded ends"square"-> extends past endpoints
Dashed Lines
<line x1="10" y1="10" x2="90" y2="10" stroke="black" stroke-dasharray="5,5" />
stroke-dasharray="5,5"= 5 units dash, 5 units gapstroke-dasharray="10,3,2,3"= complex patterns
Quick Tips
Lines have no area, so
filldoes nothingRectangles can have both
fillandstrokeBoth work with
transformfor rotation/scalingBoth use viewBox coordinates






