Sub topic 10
Making media accessible
This chapter assumes you can embed audio and video, add a track element, and write basic JavaScript event handlers. It covers what accessibility requires of media, which parts the browser handles, and which parts you must supply.
What media accessibility needs
Different users need different alternatives. The table maps each need to the thing you provide.
| User need | What you provide | WCAG criterion |
|---|---|---|
| Deaf or hard of hearing | Captions for speech and meaningful sounds | 1.2.2 (A) |
| Blind or low vision | Audio description of important visuals | 1.2.5 (AA) |
| Audio-only content | A text transcript | 1.2.1 (A) |
| Anyone who cannot use a mouse | Keyboard-operable controls | 2.1.1 (A) |
| Anyone distracted or sensitive to sound or motion | A way to pause, stop, or mute | 1.4.2 (A), 2.2.2 (A) |
A transcript helps beyond accessibility. Users can search it, translate it, and read it where they cannot play sound.
Captions versus subtitles
Captions and subtitles are not the same thing.
- Subtitles translate or transcribe dialogue for viewers who can hear the audio.
- Captions also include non-speech information, such as
[door slams]or[tense music], for viewers who cannot hear it.
Both use the track element and a WebVTT file. The kind attribute records the intent.
<video controls width="640" preload="metadata">
<source src="lecture.mp4" type="video/mp4">
<track kind="captions" src="lecture.en.vtt" srclang="en" label="English captions" default>
<track kind="subtitles" src="lecture.es.vtt" srclang="es" label="Español">
<track kind="descriptions" src="lecture.desc.vtt" srclang="en" label="Descriptions">
</video>The kind values behave differently in practice:
captionsandsubtitlesare displayed by the browser. Each shows up in the player's menu under itslabel.descriptionsis not voiced by any major browser. It exists so a script can read the cues aloud, for example through anaria-liveregion. Do not rely on it as your only audio description.chaptersis likewise not rendered by default. It gives scripts a list of named time ranges.
Use default on at most one track. Captions are better enabled by default for content whose meaning depends on speech, because users who need them may not know how to find the menu.
Audio description
Audio description narrates visual information that the soundtrack does not already convey, such as on-screen text, actions, and scene changes. In HTML you have three practical options:
- Record a second version of the video with the narration mixed in, and link to it next to the player.
- Provide a full text alternative, such as a transcript that includes the visual details.
- Write the description into the main audio, if the video is under your control. This often removes the need for a separate track.
<figure>
<video controls width="640" src="demo.mp4">
<track kind="captions" src="demo.en.vtt" srclang="en" label="English" default>
</video>
<figcaption>
Product demo.
<a href="demo-described.mp4">Version with audio description</a> |
<a href="demo-transcript.html">Read the transcript</a>
</figcaption>
</figure>Level A conformance (1.2.3) accepts either a description or a text alternative. Level AA (1.2.5) requires audio description for prerecorded video.
Transcripts for audio
An audio element has no track display area, so the transcript is the main alternative. Put it on the same page, or link to it directly beside the player.
<audio controls src="episode-12.mp3"></audio>
<p><a href="episode-12-transcript.html">Transcript of episode 12</a></p>Include speaker names and meaningful non-speech sounds. Keep the transcript in real text, never an image or a PDF scan.
Keyboard access and native controls
The controls attribute gives you the browser's built-in player. Browsers build these controls to be keyboard operable and expose them to assistive technology, though the exact keys and look differ between browsers. This is the safest default, and it is the reason to prefer it over custom controls unless you have a specific need.
Check these points when you test:
- Tab reaches the player, and the focus indicator is visible.
- The user can play, pause, seek, change volume, toggle captions, and enter full screen without a mouse.
- Nothing you add around the player traps focus.
Never hide the focus outline on a media control without replacing it. Never use tabindex="-1" on controls.
Custom controls
If you build your own, use real button elements. A button gets keyboard activation, focus, and a role for free. A div with a click handler gets none of these.
<video id="v" src="clip.mp4" width="640"></video>
<button id="toggle" type="button">Play</button>
<script>
const video = document.querySelector('#v');
const toggle = document.querySelector('#toggle');
toggle.addEventListener('click', async () => {
if (video.paused) {
try {
await video.play();
} catch (err) {
console.error('Playback failed:', err.name);
}
} else {
video.pause();
}
});
video.addEventListener('play', () => { toggle.textContent = 'Pause'; });
video.addEventListener('pause', () => { toggle.textContent = 'Play'; });
</script>The button's visible text changes with the state, so its accessible name always matches what a click will do. Updating the label from the play and pause events, not only from the click handler, keeps it correct when the user pauses with another control.
A button that keeps one label and shows state through aria-pressed is also valid. Do not combine both approaches. A button labeled "Pause" with aria-pressed="true" is announced confusingly.
Autoplay, motion, and sound
Sound that starts by itself competes with a screen reader's speech. WCAG 1.4.2 requires that audio playing for more than three seconds can be paused, stopped, or have its volume controlled independently of the system volume. The simplest rule is to avoid autoplay with sound.
Moving content that starts automatically and lasts longer than five seconds, such as a decorative background video, needs a way to pause it (2.2.2). Respect the user's motion preference too.
const bg = document.querySelector('#bg');
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
function applyMotionPreference() {
if (reduceMotion.matches) {
bg.pause();
bg.controls = true;
}
}
applyMotionPreference();
reduceMotion.addEventListener('change', applyMotionPreference);Pair this with a decorative video that has muted and playsinline, and provide a visible pause button when you do not show native controls.
Common errors
- Auto-generated captions published without review. They often misspell names and technical terms. Treat them as a first draft.
kind="subtitles"used for English captions of English audio. Usecaptionsso assistive technology can tell what the track contains.- Missing
label. The track menu shows a blank entry. - Captions that cover on-screen text. Test with the native player and check that cue positions do not hide important content.
- A transcript hidden in a collapsed section with no link. Users never find it.
- Fallback text that only says "video not supported." Include a download link so the content stays reachable.
Exercise
A page shows a 4-minute product demo with narration and a few on-screen labels. List the minimum accessibility pieces you would add, and say which kind you would use for the English caption file.
Show answer
Add an English caption file with <track kind="captions" srclang="en" label="English" default>, because the narration needs captions and the file should include meaningful sounds. Add either an audio-described version or a full text alternative, since the on-screen labels carry visual information. Link a transcript next to the player. Keep the native controls attribute so the player is keyboard operable. Do not autoplay with sound.
Exercise
Your custom play button is a div with a click listener. Name two things a keyboard user cannot do, and give the fix.
Show answer
They cannot reach the div with Tab, and they cannot activate it with Enter or Space. Replace it with <button type="button"> and update its text from the play and pause events so its accessible name always describes the next action.