HTML <track>
Tag Tutorial
The <track>
tag is used in conjunction with the <video>
and <audio>
tags to specify subtitles, captions, descriptions, chapters, or metadata for the media files.
Attributes of the <track>
tag:
Attribute | Description |
---|---|
kind | Specifies the kind of text track (subtitles, captions, descriptions, chapters, or metadata) |
src | Specifies the URL of the track file |
srclang | Specifies the language of the text track |
label | Specifies a title for the track |
Example of how to use the <track>
tag:
Let's say we have a video element and we want to add subtitles in English to it. Here's how you can use the <track>
tag:
<video controls>
<source src="video.mp4" type="video/mp4">
<track kind="subtitles" src="subtitles_en.vtt" srclang="en" label="English">
</video>
In this example, the <track>
tag specifies a subtitle track in English for the video file "video.mp4". The kind
attribute specifies that it is a subtitle track, the src
attribute specifies the URL of the subtitle file, the srclang
attribute specifies the language of the subtitle track, and the label
attribute specifies the title for the track.