Skip to content
Tutorials Center
My learning

Topics

HTML Reference Β· Images and Media

The <track> element

Reference for the HTML <track> element: kind, src, srclang, label and default, WebVTT caption files, CORS rules, accessibility notes and technical details.

The <track> element attaches a timed text track to a <video> or <audio> element. The text comes from a separate WebVTT file (.vtt) that lists short pieces of text, called cues, each with a start and end time. Browsers show caption and subtitle cues on top of the video and list the tracks in the player's captions menu.

<track> is a void element. Place it inside the media element, after any <source> elements.

HTML
<video controls src="/media/talk.mp4">
  <track kind="captions" src="/captions/talk.en.vtt" srclang="en" label="English" default>
</video>

Try it

On a real site, src points to your .vtt file and that's all. This live editor runs in a sandbox that counts as a different origin, so the example keeps the WebVTT text in the page and turns it into a data: URL with a short script.

Captions on a video

The same video on your own site:

HTML
<video controls width="480" height="270" poster="/samples/media/fractal-poster.jpg">
  <source src="/samples/media/fractal.webm" type="video/webm">
  <source src="/samples/media/fractal.mp4" type="video/mp4">
  <track kind="captions" src="/captions/fractal.en.vtt" srclang="en" label="English" default>
  <track kind="subtitles" src="/captions/fractal.es.vtt" srclang="es" label="EspaΓ±ol">
</video>

Attributes

Attribute Values Description
src URL The WebVTT file. Required.
kind subtitles (default), captions, descriptions, chapters, metadata What the text is for: a translation of the dialogue, dialogue plus sound cues for viewers who can't hear, descriptions of the picture for viewers who can't see it, chapter titles, or data for scripts that is never shown. A missing or invalid value means subtitles.
srclang Language tag (en, es, pt-BR, …) The language of the text. Required when kind="subtitles".
label Text The name shown in the player's track menu. Write it in the track's own language ("EspaΓ±ol", not "Spanish"). Labels should be unique within the same kind and language.
default Boolean Turns the track on by default. Use it on at most one captions/subtitles track per media element (and at most one descriptions and one chapters track).

It also accepts the global attributes.

Usage notes

  • Captions vs. subtitles. Captions are for people who can't hear the audio, so they include speaker names and important sounds ([door slams]). Subtitles are for people who can hear but don't understand the language, so they translate the speech only.
  • The file format. A .vtt file starts with the line WEBVTT; each cue is a timing line such as 00:01.000 --> 00:04.000 followed by its text, and cues are separated by blank lines. Serve it as text/vtt.
  • Other origins need CORS. A caption file on a different origin only loads when the media element has a crossorigin attribute and the caption server sends Access-Control-Allow-Origin. Hosting captions on the same origin as the page avoids the problem.
  • What browsers show. Built-in players display captions and subtitles. descriptions, chapters and metadata tracks load, but you need JavaScript (the TextTrack API, cuechange events) to use them.
  • Audio elements. <audio> accepts tracks too, but browsers don't display their cues; use a transcript instead.
  • Styling cues. The ::cue pseudo-element styles caption text from the page's CSS, for example video::cue { background: rgb(0 0 0 / 80%); }.

Technical summary

Content categories None
Permitted content Nothing; it is a void element
Tag omission Start tag required; must not have an end tag
Permitted parents A <video> or <audio> element, after any <source> elements and before other content
Implicit ARIA role No corresponding role
DOM interface HTMLTrackElement
Default display Not rendered; its cues appear inside the video's own display area

Browser support

Supported in every browser; the look of the captions menu and the default cue styling differ between browsers.