HTML <svg> tag
- closing tag
- required
- void element
- no
- lives inside
- anywhere in <body>
- typically holds
- shape elements like <circle>, <path>, <rect>
Where it goes
Anywhere in <body>. It needs a viewBox to set its coordinate system, and shape tags inside it (like <circle> and <path>) to draw the picture.
Example
<svg role="img" viewBox="0 0 20 20">
<title>Warning</title>
<circle cx="10" cy="10" r="8" />
</svg>Open this example in the editor →
Common mistakes
- Adding role="img" without a <title> inside. That promises a name for a screen reader (software that reads the page aloud) and then gives none.
- Forgetting viewBox. Without it, the shapes sit at raw pixel positions with no link to the drawn size, and scaling goes wrong.