html
  1. html-track-tag

HTML <track> Tag

  • The <track> tag in HTML is used to provide timed text track for HTML5 video and audio elements.
  • It is used to add subtitles, captions, descriptions, etc. to enhance the multimedia content for better accessibility.

Syntax

The basic syntax of the <track> tag is as follows:

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

The required attribute is src which specifies the URL of the text track file. Other optional attributes are:

  • kind: specifies the type of track, such as subtitles, captions, descriptions, chapters, or metadata.
  • srclang: specifies the language of the text track.
  • label: specifies the label of the text track that will be displayed to the user.

Example

Here's an example of how to use the <track> tag for captions:

<video controls>
  <source src="video.mp4" type="video/mp4">
  <track kind="captions" src="captions.vtt" srclang="en" label="English Captions">
</video>
Try Playground

Explanation

The <track> tag is used to add text tracks to HTML5 video and audio elements. The kind attribute can be used to specify the type of text track, such as subtitles, captions, descriptions, chapters, or metadata. The src attribute is used to specify the URL of the text track file and the srclang attribute is used to specify the language of the text track. The label attribute is used to provide a label for the text track which will be displayed to the user.

Use

The <track> tag is used to add supplementary text tracks to multimedia content. It is particularly useful for providing subtitles and captions for better accessibility for people who are deaf or hard of hearing, or for people who don't speak the language of the video or audio content.

Important Points

  • The <track> tag is a child element of the <video> or <audio> element.
  • The src attribute is required for the <track> tag, and the text track file must be in a suitable format such as WebVTT or SRT.
  • The kind attribute is used to specify the type of the text track.
  • The srclang attribute is used to specify the language of the text track, and the label attribute is used to provide a label for the text track that will be displayed to the user.
  • The text track file must be hosted on the same server as the video or audio file, or on a server that supports Cross-Origin Resource Sharing (CORS).

Summary

The <track> tag is used to add timed text tracks to HTML5 video and audio elements, providing subtitles, captions, descriptions, chapters, or metadata to enhance multimedia content for better accessibility and user experience. It requires the src attribute to specify the URL of the text track file, and optional attributes such as kind, srclang, and label can be used to provide additional information about the text track.

Published on: