Lesson 32 of 36
HTML Tutorial

Embeds and SVG

Embed videos and maps with iframes, and draw crisp scalable graphics with inline SVG.

3 min readBeginnerWeb FundamentalsHTML Media

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:

html
<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.com domain reduces tracking until the viewer presses play.
  • title is essential, since screen readers announce it.
  • loading="lazy" delays loading until the frame nears the viewport.
  • allow lists 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:

html
<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:

html
<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:

html
<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:

  • viewBox defines the internal coordinate system, so the image scales with its container.
  • Shapes include rect, circle, ellipse, line, polygon and path.
  • fill colours the inside and stroke the outline.
  • <title> plus role="img" gives the graphic an accessible name. A purely decorative SVG should use aria-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 title on 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

Optional

A short quiz to check what you just learned.

Questions
4
Time limit
5 min
Pass mark
70%
Best score
-