<track>

A file with subtitles, descriptions, or chapters for `<video>` and `<audio>`.

Display
not displayed
Closing tag
None, void element
Permitted content
None, empty element
On this page

Example

#
HTML
<video controls width="300" height="200" preload="none" poster="/collections/covers/nauka-javascript-dla-poczatkujacych.webp">
  <source src="/media/lekcja-js.mp4" type="video/mp4">
  <track kind="captions" src="/media/lekcja-js-pl.vtt" srclang="pl" label="Polish" default>
  <track kind="subtitles" src="/media/lekcja-js-en.vtt" srclang="en" label="English">
</video>
Preview

The video file and the subtitle files are skipped in the preview.

Definition and usage

#

The <track> element attaches a text track in the WebVTT format (a .vtt file) to a video or recording. Most often these are subtitles, but they can also be scene descriptions for blind people or a list of chapters. It is an empty element and sits inside <video> or <audio>, after the <source> elements.

The kind attribute sets the type of track: subtitles is a translation of the dialogue into another language, and captions is a full transcript for deaf people, including descriptions of sounds, for example “[music]”. The srclang attribute gives the language, and label the name shown in the player menu.

The subtitle file must come from the same domain as the page or be served with CORS headers (in which case you add the crossorigin attribute to the <video>). This is a common reason why subtitles “don’t work”.

Syntax

#
Syntax
<track kind="subtitles" src="subtitles.vtt" srclang="en" label="English">

Attributes

#
  • kind

    subtitles | captions | descriptions | chapters | metadata

    The type of track, subtitles by default. descriptions contains text descriptions of what is happening on screen, chapters chapter titles for navigation, and metadata data for scripts, invisible to the user.
  • src

    URL of the .vtt file

    The address of the WebVTT file with the track. This attribute is required.
  • srclang

    language code, e.g. `pl`, `en`

    The language of the track. Required when kind is subtitles.
  • label

    text

    The name of the track shown in the subtitle selection menu, for example “Polish” or “English”.
  • default

    boolean attribute

    Enables this track by default. Among the tracks of a single player only one can have it.

The element also supports all global attributes, such as class, id, style and hidden.

More examples

#
An example WebVTT subtitle file
Tekst
WEBVTT

00:00:00.000 --> 00:00:03.500
Hi! In this lesson you will learn about variables.

00:00:04.000 --> 00:00:08.000
A variable is a labeled box in which you store a value.

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • A .vtt file must start with the word WEBVTT, and you write times in the format 00:00:04.000 --> 00:00:08.000.
  • If you provide subtitles in several languages, set default on only one track.
  • Subtitles are displayed only in <video>. In <audio> the text tracks are available to scripts, for example to show your own transcript.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.