
Challenge · medium
HTML Video, Audio and Iframe: Accessible Media Fix
Goal: Make a video, a sound clip and an embedded page work for everyone.
Learn
Leave off the controls attribute and <audio> disappears completely. A <video> without it still shows a picture, but nobody can pause it. The video section of the HTML standard (opens in a new tab) lists every media attribute if you want the full set.
Skip autoplay. Sound or motion out of nowhere startles people and talks over screen readers, and browsers block it anyway unless the video is muted. Audio that starts by itself also breaks WCAG 2.2 success criterion 1.4.2, Audio Control (opens in a new tab).
Browsers disagree about formats. Give the video several <source> elements with a type each and the browser plays the first one it can handle. Anything else you put inside the video element, like a download link, is shown only when nothing plays. One more thing: an <iframe> needs a title, or a screen reader user has no idea what the frame holds. See the lessons on audio and video and on iframes for the details.
The short version
- Add
controlsso people can pause, play and even see the audio player. - Leave out
autoplay. Nothing should start until the visitor asks for it. - List each format in its own
<source>with atype, then add a fallback link. - Every
<iframe>gets atitlethat says what is in it.
Example
<audio controls>
<source src="t-rex-roar.mp3" type="audio/mpeg">
<a href="t-rex-roar.mp3">Download the roar</a>
</audio>Your task
This media page has five problems. Fix them:
- Give the video
controlsand takeautoplayoff the page. - Swap the video's
srcfor two<source>elements, each with atype: the .webm file (video/webm) and the .mp4 file (video/mp4). The URL is the same apart from the ending. - Inside the video, add a fallback link to the .mp4 file.
- Give the audio
controls. - Give the iframe a
titledescribing its content.
Ctrl+Enter checks your code. Try Visual edit to change the page directly, DOM tree to see how the browser reads it, and Outline to hear it like a screen reader.
Quick quiz
Frequently asked questions
How do I add a video to an HTML page?
Write a <video> element with controls. Inside it, put one <source> per file format, each with a type such as video/webm or video/mp4. Browsers play the first format they understand, which is why an open format like WebM (opens in a new tab) usually goes first. Set width and height so the page keeps the space free, and finish with a download link as a fallback.
Why does autoplay not work in my browser?
Because browsers block it. Autoplay with sound is refused until the visitor has clicked or tapped something on the site, so nobody gets a surprise blast of noise. A video that has both autoplay and muted will usually start. Even so, moving content can distract or disorient people. Give them controls and let them press play.