Skip to content
Guest
Learn HTML · Course Syllabus Show lessons
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)
ScalingInfinitely sharp at any zoomPixelates if stretched without HiDPI scaling
DOM & CSSEach shape is a DOM node (styleable & accessible)Single bitmap element drawn via JS
Best forIcons, logos, UI diagrams, simple chartsGames, photo editors, thousands of animated particles

Safe <iframe> Embeds

Always give every <iframe> two things:

  1. title="...": Required so screen-reader users know what the embedded frame contains.
  2. 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.

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind