Media, Graphics & Data · 9 min read · Beginner
Inline SVG, Canvas & Sandboxed Iframes
Choose between scalable SVG graphics and pixel-based Canvas, and embed external content securely with sandboxed iframes.
What you'll learn
- Draw crisp, resolution-independent icons and charts with inline <svg>
- Understand when to choose <svg> vs. <canvas>
- Embed external content safely using <iframe title="..." sandbox="...">
HTML gives you two native graphics engines (<svg> and <canvas>)plus <iframe> for embedding isolated documents (like the live code previews on DevPath!).
<svg> vs. <canvas>
| Feature | <svg> (Vector) | <canvas> (Raster / Pixels) |
|---|---|---|
| Scaling | Infinitely sharp at any zoom | Pixelates if stretched without HiDPI scaling |
| DOM & CSS | Each shape is a DOM node (styleable & accessible) | Single bitmap element drawn via JS |
| Best for | Icons, logos, UI diagrams, simple charts | Games, photo editors, thousands of animated particles |
Safe <iframe> Embeds
Always give every <iframe> two things:
title="...": Required so screen-reader users know what the embedded frame contains.sandbox: Restricts scripts, popups, and top-level navigation unless explicitly opted in (e.g.,sandbox="allow-scripts").
Fill-in-the-Blank Exercise
Accessible & Sandboxed Embed
Add an accessible title, lazy loading, and a restrictive sandbox attribute to the iframe.
<iframe
src="https://example.com/widget"
="Interactive weather widget"
loading=""
="allow-scripts"
></iframe>Try It Yourself: Inline SVG + Canvas Side-by-Side
Live Inline SVG & HTML5 Canvas
Live Result
Console Output
No console output yet. Try calling console.log(...) in JS.
Check Your Understanding
Score: 0 / 1
1. Which graphics element is best for crisp UI icons and logos that scale cleanly on any display?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.