Back to HTML

Captions and Subtitles with the track Element

Coding Tutorials Team 4 July 2026

Adding captions to video is one of the highest value accessibility improvements available, and it is far less work than most people assume. The file format is plain text, and the markup is one element.

Captions, subtitles and descriptions

These terms are used interchangeably in casual speech and mean different things here.

Subtitles are a translation of the dialogue, intended for viewers who cannot understand the language being spoken. They assume the viewer can hear.

Captions are for viewers who cannot hear. They include the dialogue and also the non speech audio that carries meaning: who is speaking, a door slamming, music starting, a phone ringing. This additional information is what makes them captions rather than a transcript of the words.

Descriptions are the reverse case, narrating important visual information for viewers who cannot see the screen.

The track element

Tracks are added as children of a video or audio element.

<video controls width="800" height="450"> <source src="/media/lesson.mp4" type="video/mp4"> <track kind="captions" src="/media/lesson-en.vtt" srclang="en" label="English" default> <track kind="subtitles" src="/media/lesson-fr.vtt" srclang="fr" label="Français"> </video>

The kind attribute distinguishes the types. The srclang attribute declares the language and is required for subtitles. The label attribute is what appears in the menu the viewer chooses from, so it should be the language name as a speaker of that language would write it. The default attribute selects one track initially, and only one track may carry it.

The WebVTT format

Caption files use WebVTT, which is readable plain text. A file begins with a signature line, then a blank line, then a series of cues.

WEBVTT 00:00:01.000 --> 00:00:04.500 Welcome to this introduction to CSS Grid. 00:00:04.800 --> 00:00:08.200 We will start with the container element.

Each cue has a start time, an arrow, an end time, and the text on the following lines. Times are hours, minutes, seconds and milliseconds, with the milliseconds separated by a full stop rather than a comma. That last detail is the most common cause of a file failing to parse, because the subtitle format it resembles uses a comma instead.

The blank line between cues is required. Files must be saved as UTF-8.

Writing good captions

Keep each cue to roughly two lines and time it to stay on screen long enough to read comfortably, which is usually at least a second even for a short phrase. Break lines at natural phrase boundaries rather than wherever the width runs out.

Identify speakers when it is not obvious who is talking, conventionally with the name followed by a colon. Include meaningful sounds in brackets. Do not caption every incidental noise, only what a hearing viewer would take meaning from.

Same origin restrictions

Caption files are subject to cross origin rules. A file served from a different domain will fail silently unless the correct headers are present and the video element carries a crossorigin attribute.

The simplest arrangement is to serve caption files from the same origin as the page. When they must come from elsewhere, this restriction is the first thing to check when tracks do not appear.

Automatic captions as a starting point

Speech recognition produces a usable first draft in minutes and gets names, technical terms and punctuation wrong often enough that publishing the raw output is not acceptable. Editing a generated file is considerably faster than transcribing from scratch, which makes automation genuinely useful as long as a human passes over it.

Styling captions

Caption appearance can be adjusted with a dedicated CSS pseudo-element, and the WebVTT format itself supports positioning and simple styling within the file. Support varies between browsers and is not something to depend on for legibility.

Most viewers with a strong preference set it in their operating system or browser accessibility settings, which is the right place for it. Overriding those preferences from your stylesheet is usually a step backwards, so restrain any styling to what genuinely helps against your particular video.

Chapters and metadata tracks

The kind attribute accepts chapters, which supplies navigable section markers, and metadata, which carries cues intended for scripts rather than for display. Chapter tracks turn a long video into something a viewer can jump around in, and metadata tracks are how synchronised page content, such as a slide changing alongside a lecture, is usually driven.

Captions help everyone

A large proportion of video is watched with the sound off, in offices, on public transport and in bed. Captions serve those viewers, people watching in a second language, and anyone struggling with an unfamiliar accent or poor audio quality.

They also give search engines text describing the video content, which the file itself cannot provide. The accessibility argument is sufficient on its own, and the practical benefits are substantial enough that captions are worth adding even if nobody had asked for them.