learn-html-with-phoebe / Deep dive 6.2 of 3
Learn HTML with Phoebe · Deep dive 6.2 of 3

Other people's pixels: SVG, iframes, and embeds

Your page can draw pictures out of pure text, and it can hold entire other pages inside it. Today: SVG (shapes as markup - the diagrams-as-code idea in its purest form), the iframe that powers every YouTube embed, the legacy plugins they replaced, and the template element quietly waiting for JavaScript.

🟠 Self-paced ~30 min
Inline SVG iframe embed / object template + shadow
Part 0

Why this deep dive exists

Session 3 taught you to place an image with <img>. This dive teaches the two bigger moves: drawing graphics directly in markup with SVG, and embedding whole external things - videos, maps, other pages - with <iframe>. Both are pure HTML skills, and both show up constantly in the wild: every chart export, every icon set, every YouTube embed on every blog.

Core - read carefully Self-study - recognition level ★ Try it now Orange panels are editable - type and watch
★ What you walk out with You can draw shapes, lines, and text as markup and drop them into any page. You can embed a page inside your page safely (title, sandbox, lazy loading). You recognize <object> and <template> when you meet them in view-source, and you know exactly which of today's elements need JavaScript before they do anything - honesty included.
your index.html one file, many guests <svg> drawings written as text <iframe> a whole page in a window <object> PDFs and legacy plugins <template> inert HTML, waits for JS SVG is drawn by you. iframe borrows someone else's page. object is the past. template is the future (with JS).
🔍 Click to zoom - your page embedding the world: four ways HTML brings outside things in.
Part 1 · covers MDN "Including vector graphics in HTML"

Inline SVG - drawings written as text core

SVG is an image format made of markup: instead of storing pixels, it stores instructions - "a circle here, this big, this color". Because the instructions are text, an SVG stays razor sharp at any zoom, weighs almost nothing, and can be written by hand, by a tool, or by an AI. Every diagram on this course site is exactly this.

LiveThe shape vocabulary: rect, circle, line, text5 min▶

An <svg> element is a canvas; inside it, each child element draws one thing. <rect> takes a position (x, y) and a size; <circle> takes a center (cx, cy) and a radius r; <line> connects two points; <text> writes real, selectable text. Shapes paint in source order - later elements sit on top.

Each child element draws one thing, in source order THE MARKUP THE DRAWING IT PRODUCES <svg viewBox="0 0 320 130"> <rect x="10" y="15" width="80" height="80"/> <circle cx="160" cy="55" r="40"/> <line x1="230" y1="95" x2="305" y2="15"/> <text x="12" y="122">all of this is text</text> </svg> all of this is text The viewBox is the drawing's own coordinate system - every shape paints inside it, to scale.
🔍 Click to zoom - the shapes paint in the order they're written, later on top of earlier
<svg viewBox="0 0 320 130" width="320">
  <rect x="10" y="15" width="80" height="80" rx="12" fill="#E34F26"/>
  <circle cx="160" cy="55" r="40" fill="#F8A47F"/>
  <line x1="230" y1="95" x2="305" y2="15" stroke="#2B1D14" stroke-width="4"/>
  <text x="12" y="122" font-size="14">all of this is text</text>
</svg>

One paragraph on viewBox, because it confuses everyone once: viewBox="0 0 320 130" defines the drawing's own coordinate system - "my world is 320 wide and 130 tall". The width attribute then says how big to display that world. Scale the display up or down and every shape scales with it, perfectly, because the browser is re-running the instructions, not stretching pixels.

Real world

This rhymes with everything a data person already loves. SVG is diagrams-as-code: version-controllable, diff-able, generatable. Matplotlib, plotly, and D3 all export SVG; when Claude draws you an architecture diagram, it is writing exactly these elements. Read the vocabulary once and every generated chart becomes editable text instead of a locked picture.

LiveBuild a tiny logo, then meet path4 min▶

Stack a few shapes and you have an icon. This is genuinely how favicons, logos, and UI icons get made - a circle, a letter, done. And when shapes are not enough, <path> draws anything: its d attribute is a walk ("Move to 10,80. Curve to 150,80...") that pens out any outline you can imagine.

<svg viewBox="0 0 120 120" width="110">
  <circle cx="60" cy="60" r="52" fill="#FDF0EA"
          stroke="#E34F26" stroke-width="7"/>
  <text x="60" y="80" font-size="56" text-anchor="middle"
        fill="#A6300F" font-family="Georgia">P</text>
</svg>
<svg viewBox="0 0 320 100" width="320">
  <path d="M10,80 Q85,10 160,80 T310,80"
        fill="none" stroke="#F06529" stroke-width="5"/>
</svg>
★ Try it nowRight-click any diagram on this page and Inspect. You will find the same rect, text, and path elements you just wrote - the course diagrams are hand-authored inline SVG, nothing more.
Self-studyimg src=".svg" vs inline svg - the tradeoff2 min read▶

You can use an SVG two ways, and MDN's vector graphics lesson turns on this choice:

  • As a file: <img src="logo.svg" alt="...">. Simple, cacheable, reusable across pages. But it is a sealed box - your page's CSS cannot restyle its insides.
  • Inline: paste the <svg>...</svg> straight into the body, like every playground above. Now every shape is a real element in your page - stylable with CSS, readable by screen readers via role="img" and aria-label, zero extra file requests. The cost: it bulks up your HTML and repeats on every page that uses it.

Rule of thumb: decorative or reused art → file. One-off diagrams you may want to style or tweak → inline. This course inlines everything, which is why you can inspect it all.

Part 2 · covers MDN "From object to iframe"

iframe - a page inside your page core

An <iframe> punches a window in your page and shows another document through it - complete with its own skeleton, its own styles, its own rules. It is how YouTube videos, Google Maps, and payment forms land on millions of sites that never touch the underlying code.

LiveYour first guest page3 min▶

Two attributes matter from day one: src points at the document to show, and title describes it for screen-reader users - an iframe without a title is an unlabeled door, so treat title as required. Below, the guest page is written inline via srcdoc so it renders in our sandbox; in the wild you will almost always use src="https://...".

An iframe is a whole document inside a window THE MARKUP YOUR PAGE, WITH A GUEST INSIDE <iframe title="A tiny guest page" srcdoc="<h2>Hello from inside</h2>" width="100%" height="120"> </iframe> This paragraph lives in YOUR page. Hello from inside I am a separate document. And this one lives in your page again. src or srcdoc supplies the guest document; title names it for screen-reader users.
🔍 Click to zoom - the guest document renders with its own rules, sealed inside the window
<p>This paragraph lives in YOUR page.</p>

<iframe title="A tiny guest page"
        srcdoc="<h2>Hello from inside</h2>
                <p>I am a separate document.</p>"
        width="100%" height="120"
        style="border: 3px solid #E34F26; border-radius: 10px">
</iframe>

<p>And this one lives in your page again.</p>
Meta-reveal Every orange playground on this course is an iframe. Your edits become a fresh guest document on every keystroke, sandboxed so nothing you type can touch the course page around it. You have been using today's element since Session 1.
LiveThe embed pattern: YouTube, maps, and the safety belt4 min▶

The pattern every "share → embed" button hands you is the same five lines. Our sandboxed playgrounds cannot load external sites, so this one is copy-paste for your own file - drop it in your project page and reload:

Copy-paste<iframe src="https://www.youtube.com/embed/VIDEO_ID"
  title="Video: what it shows"
  width="560" height="315"
  loading="lazy" allowfullscreen></iframe>
Honest note: this only comes alive in a real page, not in the course playgrounds - external sites refuse to load inside our no-script sandbox.
  • sandbox is the safety belt. Adding a bare sandbox attribute strips the guest of its powers: no scripts, no forms, no popups. You then hand back only what it needs, like sandbox="allow-scripts". Embedding content you do not fully trust without it is lending your page to a stranger.
  • loading="lazy" tells the browser not to fetch the iframe until the reader scrolls near it - free speed for below-the-fold embeds, same attribute you will meet again on images in deep dive 6.3.
  • Some sites refuse to be framed. If an embed shows up blank, the site likely sends headers forbidding embedding (banks and login pages do this on purpose). Use their official embed URL, not the normal page URL.
Real world

Dashboards live this way too: Tableau Public, Looker Studio, and Streamlit apps all ship "embed" snippets that are plain iframes. A data person who knows the iframe pattern can put a live dashboard into any wiki, portal, or personal page in one paste - title and lazy loading included.

Self-studyembed and object - the honest history card2 min read▶

Before iframes won, pages bolted on external content with plugins: <embed> and <object> were the sockets that Flash movies, Java applets, and PDF viewers plugged into. The plugins are gone (Flash retired in 2020), but you still meet these elements in older codebases, so recognize them:

  • <object data="report.pdf" type="application/pdf"> - the one still-legitimate use: showing a PDF inline, with fallback content between the tags for browsers that cannot.
  • <embed> - same era, fewer features, no fallback mechanism. If you are writing new code, you basically never want it.

Why iframe wins today: it embeds real web documents rather than plugin content, it has the sandbox security model, lazy loading, and a title for accessibility. MDN's own lesson title tells the story - "from object to iframe" is the direction of travel.

Part 3 · covers web.dev "Template, slot, and shadow" · recognition level

template, slot, and shadow DOM - HTML that waits for JavaScript honesty-first

One family of elements exists purely as raw material for JavaScript. This course teaches HTML, not JS - so the goal here is honest recognition: know what these look like and what they are for, so nothing in view-source ever mystifies you.

Livetemplate - the invisible element (that is the lesson)3 min▶

Everything inside a <template> is parsed and held in memory but never rendered - no display, no image loading, no effect on the page. It is a stamp waiting for JavaScript to press it, once per row of data, once per card in a feed.

<p>Before the template.</p>

<template>
  <p>Without JavaScript, you will never see me.</p>
</template>

<p>After the template. Notice the missing middle.</p>

Why it exists: before <template>, developers hid stamp-out markup in strings or hidden divs - which still loaded images and confused screen readers. The template element is the honest version: real HTML, officially inert.

Self-studyslot and shadow DOM - recognize the component model3 min read▶

Needs JavaScript - shown here so you recognize it in the wild, not to run it today. Custom elements (tags with a dash, like <user-card>) combine three ideas: a template for the stamp, a shadow DOM (a private, sealed subtree where the component's internals live, safe from the page's CSS), and <slot> - a labeled hole in the template where your content gets projected in.

Recognize this<template id="card-tpl">
  <h3><slot name="title">Untitled</slot></h3>
  <p><slot>No description.</slot></p>
</template>

<user-card>
  <span slot="title">Phoebe Fu</span>
  Data and AI person.
</user-card>
Inert until a script calls attachShadow and stamps the template. In our no-JS playgrounds this renders as plain text, so it lives in a box, not a playground.

Where you meet this daily: the <video> controls, browser date pickers, and design-system components (many Google and GitHub UI pieces) are all shadow DOM. When DevTools shows you #shadow-root, you now know what you are looking at.

Self-studyThe HTML APIs tour - where this course hands over2 min read▶

web.dev's "HTML APIs" chapter makes one big point worth carrying out of this course: every element you have learned also has a JavaScript surface. The document is queryable (querySelector finds elements the way CSS selectors do), every attribute is readable and writable from code, and rich elements expose whole method sets - <video> has play and pause, <dialog> has showModal, forms can validate themselves on demand.

Nothing to do today. Just know the door exists: the clean, semantic HTML you now write is precisely what makes the JavaScript course after this one pleasant - scripts navigate pages by the same structure and meaning you have been building since Session 1.

Homework

Try it yourself - this week ◐ 20-30 min total

Source material

Official sources covered

This dive teaches the working content of MDN's Including vector graphics in HTML and From object to iframe, plus the recognition layer of web.dev's Template, slot, and shadow chapter.

✓MDN: Including vector graphics in HTMLPart 1 - shapes, viewBox, img-vs-inline tradeoff
✓MDN: From object to iframePart 2 - iframe, sandbox, lazy loading, object/embed history
◐web.dev: Template, slot, and shadowPart 3 - concept + recognition; the JS half belongs to a JS course
◐web.dev: HTML APIsPart 3 - one-card "what exists" tour; the next course starts here
Check yourself

Three questions before you go 🎯 ◐ 90 seconds

1 · Your logo needs to stay sharp at any size AND change color with your page's CSS. Best move?

SVG stays sharp either way, but only inline SVG exposes its shapes as real elements your CSS can restyle. An img-loaded SVG is a sealed box.

2 · You embed a third-party widget you do not fully trust. Which attribute is the safety belt?

sandbox strips the guest page of scripts, forms, and popups until you explicitly hand powers back. lazy is speed, title is accessibility - both good, neither is security.

3 · A template element full of markup renders as... what?

Templates are parsed but never rendered - the invisible playground earlier was working correctly. That inertness is the feature JavaScript builds on.

Deep dive 6.2 cheat sheet · pin this

SVG = shapes as textrect (x, y, width, height), circle (cx, cy, r), line (x1, y1, x2, y2), text, path (d). Later elements paint on top.
viewBoxviewBox="0 0 W H" defines the drawing's own coordinates; width/height set display size. Scales perfectly - it re-draws, never stretches.
File vs inlineimg src=".svg" = simple, cacheable, sealed. Inline svg = stylable, accessible (role="img" + aria-label), zero requests.
iframe basicssrc + title (treat title as required). A whole separate document with its own skeleton, shown through a window.
Embed patterniframe src="...embed URL..." title loading="lazy" allowfullscreen. Blank embed? The site forbids framing - use its official embed URL.
sandboxBare sandbox strips all powers; add back only what is needed (allow-scripts...). Untrusted embed without it = lending your page to a stranger.
object / embedPlugin-era sockets. Still seen for inline PDFs (object data="x.pdf"). New code: iframe wins - security, lazy, a11y.
template / slot / shadowtemplate = inert HTML waiting for JS. slot = labeled hole for content. shadow DOM = sealed internals (#shadow-root in DevTools).