svg
Vector markup that scales cleanly and can be styled.
Learn canvas, svg as part of the HTML element system: when to use it, how it fits inside a document and what mistakes to avoid.
Graphics
SVG is markup for scalable vector graphics. Canvas is a drawing surface controlled with JavaScript.
Use SVG when the graphic has meaningful shapes, icons or scalable illustration. Use canvas when you need dynamic drawing, charts, games or pixel-level rendering.
canvas, svg. Programmatic drawing and scalable vector markup. Syntax in context
SVG content is part of the DOM. Canvas pixels are not meaningful unless you provide alternative text or surrounding explanation.
<svg viewBox="0 0 120 120" role="img" aria-label="Green progress circle"> <circle cx="60" cy="60" r="48"></circle> </svg> <canvas width="320" height="180" aria-label="Live chart preview"></canvas>
Good versus weak
<svg viewBox="0 0 120 120" role="img" aria-label="Green progress circle"> <circle cx="60" cy="60" r="48"></circle> </svg> <canvas width="320" height="180" aria-label="Live chart preview"></canvas>
<canvas width="900" height="400"></canvas>
Rules that matter
Use SVG for icons, logos, diagrams and simple illustrations.
Canvas pixels are not automatically understandable.
Use role, aria-label or surrounding text when the graphic matters.
Normal UI and text should remain HTML, not painted pixels.
Production thinking
Beginners often ask why this is not just a div with styling. The reason is that HTML is read by browsers, search engines, screen readers and future developers. Clear meaning makes the page easier to use and maintain.
SVG can be labeled. Canvas needs an accessible alternative when it communicates information.
SVG is excellent for UI assets. Canvas is excellent for visual engines, games and complex dynamic rendering.
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.