<track>

Draft

Definition

The <track> HTML element is used to specify external text tracks or captions for media elements such as <audio> or <video>. It allows you to provide subtitles, captions, descriptions, or other types of textual information that can enhance the accessibility and user experience of media content.

Here’s an example of how to use the <track> element:

<video controls>
  <source src="video.mp4" type="video/mp4" />
  <track src="subtitles.vtt" kind="subtitles" label="English" srclang="en" />
</video>

In this example, the <video> element is used to display a video, and the <source> element specifies the video source file. The <track> element is used to define an external subtitle track. The src attribute specifies the URL of the subtitle file in WebVTT format (with the .vtt extension), and the kind attribute indicates the type of track, which is “subtitles” in this case. The label attribute provides a label for the track, and the srclang attribute specifies the language of the subtitles.

By using the <track> element, you can include multiple tracks for different languages or types of captions. Users can then select the desired track using the media player’s controls.

It’s important to ensure that the subtitle files are properly synchronized with the media content and provide accurate captions or translations. You can use text editors or specialized subtitle editing tools to create or modify WebVTT subtitle files.