
HTML track Tag
The HTML <track>
tag is used to specify timed text tracks for media elements, such as audio or video. It is commonly used for displaying captions, subtitles, descriptions, or other textual information synchronized with the media playback.
Here’s an example of how the <track>
tag can be used:
<video controls>
<source src="video.mp4" type="video/mp4">
<track src="captions.vtt" kind="captions" label="English" srclang="en">
</video>
In the above example, the <track>
tag is used to add captions to a <video>
element. The src
attribute specifies the source file of the captions, which is typically in the WebVTT format (.vtt
file extension). The kind
attribute is set to “captions” to indicate that it is providing captions for the video. The label
attribute specifies the label or name of the track, and the srclang
attribute defines the language of the captions.
The <track>
tag can be used within both the <video>
and <audio>
elements to associate timed text tracks with the corresponding media. Multiple <track>
elements can be used to provide tracks in different languages or for different purposes, such as captions, subtitles, or descriptions.
It’s important to note that the browser support and appearance of the text tracks depend on the media player being used. Some media players may display the captions or subtitles by default, while others may require user interaction to enable them.
By using the <track>
tag, you can enhance the accessibility and usability of your media content by providing synchronized text tracks for users who may need captions or subtitles to understand the audio or video content.