Track and captions
Add captions and chapters with <track>.
The track element and kind
The <track> element adds text tracks to a video: captions, chapter markers or spoken descriptions. Each track links to a WebVTT file (with src) and the kind attribute sets the track type.
kind="captions" provides captions for deaf and hard-of-hearing viewers, including sound effects alongside the dialogue. kind="subtitles" is for translation.
The track element goes inside the video, after the source elements.
srclang and label
Each <track> element takes two more attributes: srclang gives the caption's language code (e.g. en, tr); label sets the human-readable name shown in the player menu (e.g. English, Turkish).
Without these two attributes, screen readers and player menus cannot pick the right track. Always give a non-empty value.
Exercise Add two captions tracks
Take the video from the previous lesson. Inside the video, after the source elements, add two <track> elements. First: kind="captions" src="/captions/black-sea-en.vtt" srclang="en" label="English". Second: kind="captions" src="/captions/black-sea-tr.vtt" srclang="tr" label="Turkish".
Show example solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Nature Doc: Black Sea</title>
</head>
<body>
<video controls>
<source src="/videos/black-sea.mp4" type="video/mp4">
<source src="/videos/black-sea.webm" type="video/webm">
<track kind="captions" src="/captions/black-sea-en.vtt" srclang="en" label="English">
<track kind="captions" src="/captions/black-sea-tr.vtt" srclang="tr" label="Turkish">
</video>
</body>
</html>
Test yourself
-
Which kind value is used for deaf and hard-of-hearing viewers?
- captions
- subtitles
- chapters
- descriptions
Show answer
captions — Correct! kind="captions" provides captions for deaf viewers, including sound effects.
-
Write the language code for the Turkish captions
<track kind="captions" src="/captions/black-sea-tr.vtt" srclang="____" label="Turkish">Show answer
<track kind="captions" src="/captions/black-sea-tr.vtt" srclang="tr" label="Turkish"> -
Match the kind value to its purpose.
- captions
- captions for deaf viewers
- subtitles
- translation subtitles
- chapters
- chapter markers
- descriptions
- audio description for blind