HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML Tag: track

The HTML <track> tag is used to specify text tracks for media elements such as <audio> and <video>. Text tracks are used to provide subtitles, captions, or other textual information related to the media content.

The <track> tag is a self-closing tag and has several attributes that can be used to specify the type of track, the language of the track, and the location of the track file.

Attributes

The following attributes can be used with the <track> tag:

  • kind: Specifies the kind of track. Possible values are "subtitles", "captions", "descriptions", "chapters", "metadata".
  • src: Specifies the URL of the track file.
  • srclang: Specifies the language of the track file using the ISO 639-1 language code.
  • label: Specifies a label for the track.
  • default: Specifies that the track should be enabled by default.

Examples

Here are some examples of how the <track> tag can be used:

Subtitles

The following example shows how to add subtitles to a video:

<video controls>
  <source src="video.mp4" type="video/mp4">
  <track kind="subtitles" src="subtitles_en.vtt" srclang="en" label="English">
  <track kind="subtitles" src="subtitles_fr.vtt" srclang="fr" label="Français">
</video>

In this example, two subtitle tracks are added to the video. The first track is in English and the second track is in French. The kind attribute is set to "subtitles" and the src attribute is set to the URL of the subtitle file. The srclang attribute is set to the language of the subtitle file using the ISO 639-1 language code. The label attribute is used to provide a label for the track.

Captions

The following example shows how to add captions to a video:

<video controls>
  <source src="video.mp4" type="video/mp4">
  <track kind="captions" src="captions_en.vtt" srclang="en" label="English">
  <track kind="captions" src="captions_fr.vtt" srclang="fr" label="Français">
</video>

In this example, two caption tracks are added to the video. The kind attribute is set to "captions" and the src attribute is set to the URL of the caption file. The srclang attribute is set to the language of the caption file using the ISO 639-1 language code. The label attribute is used to provide a label for the track.

Descriptions

The following example shows how to add descriptions to a video:

<video controls>
  <source src="video.mp4" type="video/mp4">
  <track kind="descriptions" src="descriptions_en.vtt" srclang="en" label="English">
  <track kind="descriptions" src="descriptions_fr.vtt" srclang="fr" label="Français">
</video>

In this example, two description tracks are added to the video. The kind attribute is set to "descriptions" and the src attribute is set to the URL of the description file. The srclang attribute is set to the language of the description file using the ISO 639-1 language code. The label attribute is used to provide a label for the track.

References

Activity