HTML: track
The <track> element adds a text track, such as captions or subtitles, to a video or audio element.
What you will learn
- How to connect a WebVTT file to media
- What kind, src, srclang, and label mean
- Why captions improve accessibility
Caption example
<video controls>
<source src="lesson.mp4" type="video/mp4">
<track kind="captions" src="captions-en.vtt"
srclang="en" label="English" default>
</video>The src points to a WebVTT text file. kind describes the track, srclang identifies its language, and label is shown to users when choosing a track.
Choose the track kind
captions: spoken dialogue and meaningful sounds for people who cannot hear the audiosubtitles: translated dialoguedescriptions: text descriptions of visual information
Choose the kind that matches the purpose. A transcript outside the player can still be useful and searchable.
Common mistakes
- Use a valid WebVTT file and a correct relative or absolute URL.
- Set the language code accurately and give users a clear label.
- Do not assume captions are optional for important spoken or sound-based information.