In HTML5, the <track> tag is used to add subtitles, captions, or other text tracks to a <video> or <audio> element.
Syntax of <track> Tag
<video width="600" height="340" controls>
<source src="movie.mp4" type="video/mp4">
<track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
<track src="subtitles_es.vtt" kind="subtitles" srclang="es" label="Spanish">
</video>
Attributes of <track>
- src → File path of the subtitle (usually in .vtt format).
- kind → Type of text track:
- subtitles → Translated dialogue.
- captions → Includes sounds & effects (for deaf/hard-of-hearing).
- descriptions → Audio descriptions of video.
- chapters → Navigation points.
- metadata → Custom data (not shown to user).
- srclang → Language of the track (e.g., en, es, fr).
- label → A user-friendly label (displayed in the player).
- default → Specifies that this track should be the default.
Example with English Subtitles
<video width="600" controls>
<source src="movie.mp4" type="video/mp4">
<track src="english.vtt" kind="subtitles" srclang="en" label="English" default>
</video>