LibraryHTMLImages and Media

Images and Media

Add responsive images, audio, and video without leaving accessibility behind.

Updated Tested with HTML Living Standard

Media can explain what text cannot, but it also affects performance and accessibility. The right markup gives browsers enough information to load it efficiently.

Images with purpose

Every img needs an alt attribute. Describe informative images; use an empty value for decoration so assistive technology can skip it.

profile.html
<img
  src="ada-lovelace.webp"
  alt="Portrait of Ada Lovelace writing at a desk"
  width="960"
  height="640"
  loading="lazy"
/>

Width and height reserve space before the image arrives, reducing layout movement. Lazy loading is useful below the initial viewport, but the primary hero image should usually load normally.

Captions and responsive sources

diagram.html
<figure>
  <picture>
    <source srcset="layout-dark.webp" media="(prefers-color-scheme: dark)" />
    <img src="layout-light.webp" alt="Three-column page layout" width="1200" height="700" />
  </picture>
  <figcaption>The same layout in both color schemes.</figcaption>
</figure>

Use picture when the content or crop should change. Use srcset and sizes when the same image needs multiple resolutions.

Audio and video

lesson-media.html
<video controls width="720" poster="lesson-cover.webp">
  <source src="lesson.webm" type="video/webm" />
  <track kind="captions" src="captions-en.vtt" srclang="en" label="English" default />
  Your browser cannot play this video.
</video>

Keep this

Supply useful alternatives, intrinsic dimensions, appropriate loading behavior, and controls that leave playback in the learner's hands.

Your place is saved on this device.