BMIS 235 · HTML-2 · Mind, Body, Craft

Embedding 101

Bring images, videos and live tools into a web page, understand who controls each piece, and fix them when they break.

Start here Why embed? Owned, linked, embedded, built Live examples Step-by-step guides

Start here

The problem

A page that breaks without telling you why

In HTML-2 you get a page where some pictures, links and videos work and others don't. The code looks almost the same, and one wrong letter is enough to break something. This site teaches you how each kind of embed works and how to find what's wrong.

The end goal

By the end, you should be able to…

  • Add an image, a YouTube video and a map or chart to a page with correct syntax.
  • Make a picture jump to a section of the page.
  • Explain who controls each piece: owned, linked, embedded or built.
  • Find and fix broken file names, links, video addresses and embed code in the pencil editor.
  • Read and change a small script, like a dark mode button.

How to use this site

  1. Read the guide. This page explains why embedding matters, shows live examples, and walks through each skill step by step.
  2. Listen. The Podcast explains the same ideas out loud, for when you'd rather hear it.
  3. Practice on real code. In Scenarios, you fix broken code in a live editor and see the result right away.
  4. See a finished example. My Gallery is a real page built by hand with every skill from this site. Look through it before you test yourself.
  5. Check yourself. The Quiz tests correct syntax and spotting errors.
  6. Track progress. My progress shows what to review.

Why embed?

Images & video

Show, don't just tell

A picture or a short video can explain an idea faster than paragraphs of text. Visual media makes a page easier to understand at a glance.

Jump links

Shortcuts that guide

Clickable images and "jump" links let visitors go straight to what interests them, so a long page still feels organized and easy to move around.

Maps & dashboards

Tools that respond

Interactive embeds, like a map you can zoom or a chart you can hover over, turn a page into a tool that adapts to what each visitor needs.

Owned, linked, embedded, built

Everything on a web page gets there one of four ways. Ask each time: who controls it?

Four ways content gets onto a page: owned, linked, embedded, built

Owned

A file in your repo, like images/sunset.jpg. You control it. It only changes when you change it.

Linked

A file on someone else's site, pointed to by its full https:// address. They control it; if it moves, it breaks on your page.

Embedded

A live window into another service, like YouTube or Google Maps. It runs on their end, inside a box on your page.

Built

Code in your page that does something, like the dark mode button. You control it.

Three kinds of embeds: static (just shows something), interactive (your clicks change your own view, nothing is saved, like a map) and two-way (you send information and they keep it, like a form). Responses to an embedded Google Form are stored by Google, not on your site.

Live examples

Each of these is working on this page right now. The code that makes it work is underneath.

Owned · image
A simple sunset over hills
<img src="images/sunset.svg" width="400" height="260" alt="A simple sunset over hills">

Click to jump: Jump to the video example ← this small image is a jump link to the video below.

Embedded · video
<a id="demo-video"></a>
<iframe width="560" height="315" src="https://www.youtube.com/embed/4L98ssI5Vxw" title="YouTube video player" allowfullscreen></iframe>
Embedded · interactive map
<iframe src="https://www.google.com/maps/embed?pb=..." width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="strict-origin-when-cross-origin"></iframe>

Try zooming and dragging. That's the "interactive" part, and it runs on Google's side.

Built · a little code

This box is the "embed block." It's always the opposite color of the area around it.
var lightColor = "#F4EDDC";
var darkColor  = "#143A30";
var dark = false;

function paint() {
  var box = document.getElementById("demo-box");
  box.style.backgroundColor = dark ? lightColor : darkColor;
  box.style.color = dark ? "black" : "white";
  box.parentElement.style.backgroundColor = dark ? darkColor : lightColor;
}
function toggleDemo() { dark = !dark; paint(); }
paint();

Step-by-step guides

Each guide covers the steps, the correct syntax, and how to spot errors in the pencil editor. Tap a guide to open it.

1 Add an image

An image is owned when the file lives in your repo, and linked when src points to a full web address on someone else's site.

Step by step

  1. Put the image file in your repo: on GitHub, Add file → Upload files, then commit.
  2. Write an <img> tag whose src is the file name exactly, including any folder, capital letters and the extension.
  3. Add alt text that describes the picture, plus a width and height.
  4. Commit, wait 1–2 minutes, and check the live page.

Correct syntax

Owned (a file in your repo)

<img src="images/sunset.jpg" width="400" height="300" alt="Sunset over the hills">

Linked (a file on another site)

<img src="https://example.com/photos/sunset.jpg" width="400" height="300" alt="Sunset over the hills">
Spotting errors in the pencil editor
  • A broken-image icon means the src doesn't match a real file. Open your repo's file list next to the code and compare them letter by letter.
  • Check capitals: Sunset.jpg and sunset.jpg are different files on GitHub Pages.
  • Check the extension: .jpg, .jpeg and .png are not interchangeable.
  • Check the folder: if the file is in images/, the src must start with images/.
  • Check the quotes: every attribute value needs an opening and closing ".
  • A linked image can break later if the other site moves or deletes it. That's out of your control.

Practice it: Scenarios · Quiz · Podcast

2 Make a picture jump to a section

A jump link has two halves: a link that says where to go, and a name tag at the destination. They must match exactly.

Step by step

  1. Right above the destination (for example a video), add an empty anchor with an id: <a id="cooking-video"></a>.
  2. Wrap the picture in a link whose href is # plus that same id.
  3. Make sure the closing </a> comes after the <img>, so the picture is inside the link.
  4. Add a "To top" link the same way: <a id="top"></a> at the top, <a href="#top"> at the bottom.

Correct syntax

The link (the picture you click)

<a href="#cooking-video"><img src="images/cooking.jpg" width="400" height="400" alt="Cooking show"></a>

The destination (right above the video)

<a id="cooking-video"></a>
Spotting errors in the pencil editor
  • If clicking does nothing, compare the text after # in the href with the id. They must match letter for letter.
  • Look for small differences: #cookingvideo vs cooking-video, or #Cooking vs cooking.
  • The # goes only in the href, never in the id.
  • Each id can be used only once per page.
  • If the picture isn't clickable at all, check that the <img> sits between <a href...> and </a>.

Practice it: Scenarios · Quiz · Podcast

3 Embed a YouTube video

A video is embedded: a live window into YouTube, which runs on YouTube's side. YouTube has two kinds of links, and only one of them works inside an <iframe>.

Step by step

  1. On YouTube, click Share → Embed and copy the code. Or build it yourself from the video's ID, the letters after watch?v=.
  2. Use the embed address in src: https://www.youtube.com/embed/VIDEO_ID.
  3. Paste the whole <iframe> … </iframe> where you want the video.
  4. Commit, then press play on the live page.

Correct syntax

Watch link (for YouTube itself; won't play in an iframe)

https://www.youtube.com/watch?v=4L98ssI5Vxw

Embed link (goes in the iframe)

<iframe width="560" height="315" src="https://www.youtube.com/embed/4L98ssI5Vxw" title="YouTube video player" allowfullscreen></iframe>

Shorts work the same way

/shorts/VIDEO_ID  becomes  /embed/VIDEO_ID
Spotting errors in the pencil editor
  • If the video box is blank or says it refused to connect, the src is probably a watch link. Swap watch?v= for embed/.
  • Compare the broken video's src with a video that works on the same page. The difference is usually right there.
  • youtu.be/ID and /shorts/ID links also need to become /embed/ID.
  • Copy the whole ID. YouTube IDs are 11 characters, and missing one breaks the video.
  • "Video unavailable" means the owner blocked embedding. That's not your code: pick another video.

Practice it: Scenarios · Quiz · Podcast

4 Embed a map or dashboard

Maps and charts are interactive embeds: viewers can zoom, pan or hover, and it all runs on the other company's site. You almost never write the iframe yourself. The site gives you the code.

Step by step

  1. Google Maps: search for a place, click Share → Embed a map → Copy HTML.
  2. Our World in Data: open a chart, click Share → Embed, copy the code.
  3. Paste the whole thing, from <iframe to </iframe>, into the section where it belongs.
  4. Change the section's heading to say what the map or chart shows. Commit and test zooming on the live page.

Correct syntax

What Google gives you (shortened here)

<iframe src="https://www.google.com/maps/embed?pb=..." width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="strict-origin-when-cross-origin"></iframe>
Spotting errors in the pencil editor
  • If you see a plain link instead of a map, you pasted the page address, not the embed code. The code must start with <iframe.
  • If everything below the map disappears, the paste is incomplete: check for the closing </iframe> and that no quote mark is missing.
  • Look for duplicate attributes, like two width= values in one tag. The browser uses only the first, so the size may not be what you expect.
  • Make sure the iframe is inside the right section (between its opening and closing tags).
  • For charts, use the archived embed version so it keeps working.

Practice it: Scenarios · Quiz · Podcast

5 Make the page run a little code

A script is built content: code in your page that does something, like a dark mode button. The HTML-2 script has five parts.

Step by step

  1. Two colors: lightColor and darkColor. These are the lines you change.
  2. A memory: dark is false (light mode) or true (dark mode).
  3. paint() colors the page one color and the embed block the other.
  4. toggleDark() runs on every click: it flips dark, then calls paint().
  5. One last paint() colors the page when it first loads.

Correct syntax

The button

<button onclick="toggleDark()">Dark mode on / off</button>

The colors you change

var lightColor = "#F4EDDC";
var darkColor  = "#143A30";

Finding the block it recolors

var block = document.getElementById("embed-block");
<!-- must match: -->
<section id="embed-block">
Spotting errors in the pencil editor
  • If the button does nothing, compare the name in onclick="..." with the function name. toggleDark() and toggledark() are different.
  • The text in getElementById("...") must match an id on the page exactly.
  • Colors need quotes and a #: "#143A30".
  • Pick two colors far apart (one light, one dark) so the text stays readable in both modes.
  • Test both modes before you submit: click the button twice.

Practice it: Scenarios · Quiz · Podcast

To top