<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
Example
#<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>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
#<track kind="subtitles" src="subtitles.vtt" srclang="en" label="English">Attributes
#kind
subtitles | captions | descriptions | chapters | metadata
The type of track,subtitlesby default.descriptionscontains text descriptions of what is happening on screen,chapterschapter titles for navigation, andmetadatadata 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 whenkindissubtitles.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
#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
.vttfile must start with the wordWEBVTT, and you write times in the format00:00:04.000 --> 00:00:08.000. - If you provide subtitles in several languages, set
defaulton 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.