svg
The root vector graphic element.
Learn HTML SVG with practical examples for rich HTML features, native browser behavior, accessibility, performance, SEO and live practice.
HTML advanced
SVG is HTML-friendly XML markup for scalable vector graphics. It is excellent for icons, logos, diagrams, simple illustrations and data visuals.
Unlike canvas, SVG shapes are elements in the DOM. They can be styled, animated, labeled and inspected.
Inline SVG is powerful, but it should still be accessible and clean. Decorative icons can be hidden; meaningful graphics need labels or text alternatives.
The root vector graphic element.
Defines the internal coordinate system.
Draws complex shapes.
Can label meaningful inline SVG.
Syntax and behavior
If an SVG is decorative, hide it from assistive technology. If it is meaningful, give it a label.
<svg viewBox="0 0 120 120" role="img" aria-labelledby="logo-title"> <title id="logo-title">Course progress badge</title> <circle cx="60" cy="60" r="52" fill="#101a2d"></circle> <path d="M34 64 L52 82 L88 38" fill="none" stroke="#8cffc1" stroke-width="10"></path> </svg>
<svg> <path d="M10 10 L90 90"> </svg>
Rules that matter
These elements can create rich interfaces, but they still need clear purpose, safe fallbacks and production discipline.
It makes SVG scalable and predictable.
Use aria-hidden="true" when the graphic adds no information.
Use title, aria-label or surrounding text.
Design tools often export unnecessary metadata.
Icons can inherit text color cleanly.
Large illustrations can make HTML hard to maintain.
Production thinking
This matters because SVG can look like an image while behaving like structured markup. That gives developers control and responsibility.
Meaningful SVG needs an accessible name. Decorative SVG should not be announced as random graphic noise.
Use SVG sprites, optimized inline SVG or external files depending on caching, styling and reuse needs.
SVG text and labels can provide context, but important page copy should still exist as normal HTML text.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.