<track>
The <track>
tag is used to provide subtitles, captions, or temporal metadata to a video or audio file.
It is always used in combination with the <video>
or <audio>
tags. This tag improves accessibility by allowing users to follow the content, even without sound or in another language. Use subtitles as much as you can! 😋
Structure and syntax of the <track>
tag
Basic structure and syntax
The <track>
tag is a self-closing tag (it closes itself) that has no content or closing tag. It is placed inside the <video>
or <audio>
tags.
Let's take a small example:
<track
kind=[track type]
src=[path to the subtitle file]
srclang=[language code]
label=[track description] />
The <track>
tag consists of four important attributes:
kind
: Defines the type of track. For example:- "subtitles" for subtitles;
- "captions" for captions detailing sounds and dialogues;
- "descriptions" for audio descriptions of visual content (such as an image);
- "chapters" to provide chapters of the audio or video track (and thus offer clickable elements);
- "metadata" for additional information.
src
: Specifies the URL of the file containing the subtitles;srclang
: Defines the language of the track with an ISO 639-1 code, for example fr for French, en for English;label
: Adds a user-visible description that will be displayed on the player;default
: If this attribute is present, this track will be activated by default (useful when you have multiple subtitle languages).
Usage examples
For a video
<video controls>
<source src="videos/sample.mp4" type="video/mp4">
<track kind="subtitles" src="subtitles_en.vtt" srclang="en" label="English" default>
<track kind="subtitles" src="subtitles_fr.vtt" srclang="fr" label="French">
</video>
In this example:
- The first track (English) is activated by default thanks to the
default
attribute. - A second track in French is available.
For an audio track
<audio controls>
<source src="audio/podcast.mp3" type="audio/mpeg">
<track kind="captions" src="captions_en.vtt" srclang="en" label="English">
</audio>
Here, we offer an audio file "audio/postcast.mp3"
followed by a subtitle track "captions_en.vtt"
in English.
Attributes
Attributes specific to the <track> tag
Attribute | Description | Possible values |
---|---|---|
kind | Indicates the type of track. | subtitles , captions , descriptions , chapters , or metadata |
src | Specifies the path to the subtitle or caption file. | Example: subtitles_en.vtt |
srclang | Defines the language of the track using an ISO 639-1 code. | Example: en (English), fr (French), es (Spanish) |
label | Provides a user-readable description, displayed in the menus of video/audio players supporting multiple tracks. | Example: English , French |
default | Defines this track as active by default. | None (if present, this track will be selected by default) |
General attributes
All classic attributes such as title
, class
, or id
can also be used on the <track>
tag.
Browser compatibility
Browser | Compatibility with <track> |
---|---|
Chrome | Yes |
Firefox | Yes |
Safari | Yes |
Edge | Yes |
Internet Explorer 10+ | Partially |