- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <track> Tag
HTML Tags
HTML <track> Tag
The track tag adds captions or subtitles to a video. You write the text in a small WebVTT file, point a track at it, and the browser shows a "CC" button in the player. One line of HTML makes a video usable for deaf viewers and anyone watching with the sound off.
<track> goes inside the video tag (or audio), after the <source> elements. It is a void element: no closing tag.
Syntax
html
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">Attributes
| Attribute | Description | Example |
|---|---|---|
| src | Specifies the URL of the track file (usually a .vtt file). | src="captions.vtt" |
| kind | Defines the type of text track: subtitles, captions, descriptions, chapters, metadata. | kind="subtitles" |
| srclang | Specifies the language of the track text (ISO language code). | srclang="en" |
| label | Provides a title for the track (shown to users). | label="English Subtitles" |
| default | Marks the track as the default one when multiple tracks are available. | default |
The kind values mean different things: subtitles translate the speech for people who can hear but do not understand the language; captions also describe sounds, like "[door slams]", for deaf viewers; descriptions describe what is happening on screen; chapters let viewers jump between sections.
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Track Tag Example</title>
</head>
<body>
<h2>Example: Adding Subtitles to a Video</h2>
<video width="640" height="360" controls crossorigin="anonymous">
<source src="https://ik.imagekit.io/html5andcss3/lesson-samples/sample_video.mp4" type="video/mp4">
<track src="https://ik.imagekit.io/html5andcss3/lesson-samples/hindi_subtitles.vtt" kind="subtitles" srclang="hi" label="Hindi" default>
<track src="https://ik.imagekit.io/html5andcss3/lesson-samples/spanish_subtitles.vtt" kind="subtitles" srclang="es" label="Español">
Your browser does not support the video tag.
</video>
</body>
</html>The video player gets a captions menu with Hindi and Español. Hindi is on by default because of the default attribute.
What a WebVTT file looks like
subtitles_en.vtt
text
WEBVTT
00:00:01.000 --> 00:00:04.000
Welcome to the HTML video lesson.
00:00:04.500 --> 00:00:08.000
Today we will add captions.It is plain text: the word WEBVTT on the first line, then each caption with a start and end time. Save it with the .vtt extension.
Why captions sometimes do not show
- Different domain. A track file on another domain needs CORS headers on that server, and
crossoriginon the<video>, as in the example. - Opened from your computer. Many browsers refuse to load track files from a
file://page. Test on a local web server. - Wrong format. SRT subtitle files do not work; convert them to WebVTT. The main differences are the
WEBVTTheader and a dot instead of a comma in the times.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Partially |
HTML <track> Tag exercises
Add subtitles
Make a video player with controls for https://ik.imagekit.io/html5andcss3/lesson-samples/sample_video.mp4. Add subtitles in Hindi (hi) from https://ik.imagekit.io/html5andcss3/lesson-samples/hindi_subtitles.vtt
Result
