Not everything has to be hosted by you. Video platforms and map services provide embed codes, and SVG lets you draw sharp graphics with markup.
Embedding a hosted video#
Platforms such as YouTube give you an <iframe> snippet. Here is a tidy, accessible version:
<iframe
width="560" height="315"
src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
title="A tour of the Brew and Byte kitchen"
loading="lazy"
allow="accelerometer; encrypted-media; picture-in-picture"
allowfullscreen></iframe>Replace VIDEO_ID with the real identifier from the video's address. Notes:
- The
youtube-nocookie.comdomain reduces tracking until the viewer presses play. titleis essential, since screen readers announce it.loading="lazy"delays loading until the frame nears the viewport.allowlists browser features the embed may use.
To keep a video responsive, CSS can set aspect-ratio: 16 / 9 and width: 100% on the iframe, instead of fixed pixel sizes.
Embedding a map#
Mapping services also provide iframe code:
<iframe
src="https://www.openstreetmap.org/export/embed.html?bbox=83.97,28.20,83.99,28.22&layer=mapnik"
title="Map showing the location of Brew and Byte"
width="600" height="400"
loading="lazy"></iframe>
<p><a href="https://www.openstreetmap.org/#map=16/28.21/83.98">View the larger map</a></p>Always include a text alternative, such as the address and a link to a full map. Embedded maps are hard to use with a keyboard or screen reader, and the visible address helps everyone.
SVG: scalable vector graphics#
SVG is an XML-based image format that describes shapes with maths instead of pixels, so it stays crisp at any size and often has a tiny file size. It is ideal for logos, icons and simple illustrations.
You can reference an SVG file like any image:
<img src="images/cup-icon.svg" alt="Coffee cup icon" width="48" height="48">Or write it inline in your HTML, which lets CSS and JavaScript style its parts:
<svg width="120" height="120" viewBox="0 0 120 120" role="img" aria-labelledby="cup-title">
<title id="cup-title">Steaming coffee cup</title>
<!-- cup body -->
<rect x="20" y="50" width="60" height="50" rx="8" fill="#6b3e26"/>
<!-- handle -->
<circle cx="88" cy="75" r="14" fill="none" stroke="#6b3e26" stroke-width="6"/>
<!-- steam -->
<path d="M40 40 Q45 30 40 20 M60 40 Q65 30 60 20" stroke="#999" stroke-width="3" fill="none"/>
</svg>The basics:
viewBoxdefines the internal coordinate system, so the image scales with its container.- Shapes include
rect,circle,ellipse,line,polygonandpath. fillcolours the inside andstrokethe outline.<title>plusrole="img"gives the graphic an accessible name. A purely decorative SVG should usearia-hidden="true".
SVG files can contain scripts, so only use SVGs you trust and never accept uploaded SVGs without sanitising them.
Common mistakes#
- Embedding without a
titleon the iframe. - Fixed pixel sizes that overflow on phones.
- No text alternative for the map.
- Missing
viewBox, so the SVG will not scale. - Embedding too many third-party widgets.
Try it yourself#
Embed a video of your choice using the privacy-friendly domain, with a descriptive title and lazy loading. Add a map of your town and write the address below it. Then draw your own simple icon in inline SVG, for example a house made from a rectangle and a triangle, and give it an accessible name.
Recap#
Embed hosted videos and maps with titled, lazy-loaded iframes and add text alternatives. Use SVG for scalable graphics, set a viewBox, give meaningful graphics an accessible name, and treat third-party content with care.
Check your understanding
Lesson quiz
OptionalA short quiz to check what you just learned.
- Questions
- 4
- Time limit
- 5 min
- Pass mark
- 70%
- Best score
- -