HTML Foundations·Beyond the basics

Media and embeds

Add images and video that load fast, adapt to the screen and make sense without them.

Beginner 13 min read Lesson 12 of 480 Challenge included
What you will be able to do
  • Write useful image alternatives
  • Serve responsive images
  • Embed video and iframes safely

Media is content. Every image needs a text alternative, every video needs captions and every embed needs a title. Reserve space so the page does not jump while loading.

media.htmlHTML
<figure>
  <img
    src="avatar-320.jpg"
    srcset="avatar-320.jpg 320w, avatar-640.jpg 640w"
    sizes="(min-width: 700px) 320px, 90vw"
    width="320"
    height="320"
    alt="Amina Rahman smiling at a desk"
    loading="lazy"
    decoding="async"
  />
  <figcaption>Amina Rahman, learning designer</figcaption>
</figure>

<video controls preload="metadata" poster="cover.jpg">
  <source src="intro.webm" type="video/webm" />
  <source src="intro.mp4" type="video/mp4" />
  <track kind="captions" src="intro.vtt" srclang="en" label="English" default />
</video>

<iframe
  src="https://example.com/embed"
  title="Course preview"
  loading="lazy"
></iframe>
Live exampleA responsive figure
AttributeWhy it matters
altReplaces the image for screen readers and failed loads
width / heightReserves space and prevents layout shift
loading="lazy"Defers offscreen images until needed
srcset / sizesLets the browser pick an appropriate file
title on iframeNames the embedded document
Your turn

Accessible profile image

Easy

Add a figure with a 320 by 320 image, useful alt text, lazy loading and a caption.

HTML · starter
<figure>

</figure>
Check your understanding before moving on.
Knowledge checkQuestion 1

Which attribute provides the text alternative for an image?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Metadata and sharing
Lesson 12 of 480 · 0% of course