Description
The HTML element <track>
is used to specify a text track for <audio>
and <video>
elements.
A text track can be a caption, subtitle, or other files containing the text that should be visible when the media playing.
Usually, the tracks are formatted in WebVTT format with the file extension of .vtt
.
The below table summarizes its usage.
Usage Details | |
Placement | It is displayed within the media elements like <video> and <audio> . |
Contents | None. It is an empty element. |
Tags | Opening tag: required; Closing tag: forbidden |
Versions | HTML 5 |
Syntax
Here is the basic syntax of the <track>
element.
<track src="URL">
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example - HTML Element track</title>
</head>
<body>
<video controls="controls">
<source src="/assets/videos/shuttle.mp4" type="video/mp4">
<source src="/assets/videos/shuttle.ogv" type="video/ogg">
<track src="/assets/videos/subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
Oops, Your browser does not support the HTML5 Video element.
</video>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <track>
element.
Attribute Type | Details |
Element-Specific Attributes | The tag <track> has some element-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <track> supports the HTML Global Attributes. |
Event Attributes | The tag <track> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <track>
element.
Attribute | Value | Required | Description |
src |
URL | Yes | Specifies the URL of the track file. |
default |
default |
No | Specifies the track should be enabled unless the user's preferences indicate that another track is more appropriate. |
kind |
captions, chapters, descriptions, metadata, subtitles | No | Specifies the kind of text track. |
label |
text | No | Specifies the title of the text track. |
srclang |
language-code | No | Specifies the language of the track text data. This attribute must be defined if the attribute kind is set to the value subtitles . |
Browser Compatibility
The tag <track>
is supported in all modern browsers.
- Google Chrome 18+
- Internet Explorer or Edge 10+
- Firefox 31+
- Apple Safari 6+
- Opera 15+