LessonLesson 21 of 34

Audio, video, captions, and useful media alternatives

Publish media with native controls, source fallbacks, captions, transcripts, and realistic loading behavior.

Intermediate5 min readLearn · Practice · Review

Published by HTML Code Runner · AI-assisted material · Independent editorial review pending · Editorial policy

On this page

Learning objectives

Choose native media elements; provide timed text and transcripts; distinguish format support from autoplay permission.

Prerequisites

Understand file paths, image alternatives, and basic semantic page structure. Prepare legally usable local media files for testing.

A player is part of a content system

Audio and video embed media with a browser playback interface when controls is present. The browser can handle play, pause, seeking, volume, and other native operations. A custom player requires substantially more behavior and accessibility work, so native controls are a useful starting point.

The source element can offer different media resources. Its type tells the browser which MIME type and, when supplied, codecs are expected. Container names and codecs are different: an MP4 file is a container, and its actual encoded tracks affect compatibility. Test the files you intend to publish rather than assuming every file with one extension will play everywhere.

Make the information available beyond sound and motion

Captions represent speech and meaningful non-speech audio, such as a door slamming or an alarm. Subtitles commonly provide dialogue, often in another language, but do not necessarily convey all audio information. A transcript offers a separate text representation that can be read, searched, and used without playing the media.

The track element attaches timed text, commonly in WebVTT format. Use a meaningful label and the correct srclang. A default track is a preference, not a guarantee that every user agent will display exactly what you expect. Ensure the media server serves files correctly and that cross-origin policies permit the resources you use.

If essential information appears only visually, captions alone are insufficient. Describe it in narration, audio description, or a suitable text alternative. Plan these alternatives while producing the content, because retrofitting them after editing can be much harder. A tutorial that says click here while pointing silently at a button needs more than a transcript of those two words.

Respect the viewer’s context

Avoid surprising autoplay with sound. Browser policies can block playback even when autoplay is requested. A script calling play receives a promise that may reject, so the interface must remain usable when playback does not start. Muted looping decoration still needs consideration for motion preferences and distraction.

Preload is a hint about resource fetching, not a guaranteed download plan. Metadata may be enough for a long lecture list; eager downloads of many videos can waste bandwidth. A poster gives a useful starting image for video, while explicit dimensions help reserve layout space. Provide a clear fallback link when the media cannot be played.

Working example

<video controls width="640" height="360" preload="metadata" poster="workshop-poster.jpg">
  <source src="workshop.mp4" type="video/mp4">
  <source src="workshop.webm" type="video/webm">
  <track kind="captions" src="workshop-en.vtt" srclang="en" label="English" default>
  <p><a href="workshop.mp4">Download the workshop video</a>.</p>
</video>
<p><a href="workshop-transcript.html">Read the transcript</a>.</p>

Another example

<figure>
<audio controls preload="none"><source src="oral-history.mp3" type="audio/mpeg"><a href="oral-history.mp3">Download the interview</a></audio>
<figcaption>Interview with the community garden coordinator.</figcaption>
</figure>

Expected output

With the declared files served locally, the browser displays native playback controls and can expose the caption track. The isolated playground blocks network media loading, so these examples are intended for a local HTTP server with real assets.

Common mistakes

Do not publish an empty captions file and assume the requirement is satisfied. Do not rely on autoplay for essential content. Check codec support, MIME types, paths, caption timing, speaker identification, and the difference between decorative and informative video.

Accessibility and browser notes

Operate the player without a pointer, enable captions, and read the transcript independently. Test that controls remain visible at zoom and that a keyboard user can leave the player. Native controls differ between browsers, so verify the actual target combinations.

Practice

Write a short WebVTT caption file for a clip containing a welcome and a bell, then explain why the bell belongs in captions.

Review the solution and reasoning
WEBVTT

00:00.000 --> 00:02.500
Welcome to the community workshop.

00:03.000 --> 00:04.000
[Bell rings]

The timing associates each cue with the media. The bell conveys audio information beyond speech, so including it helps viewers who cannot hear it understand the event. Real captions need accurate timing and review against the full recording.

Related lessons

Specifications and further reading

One more skill in your toolkit.

Finished the explanation and exercise? Save your progress.