HTML5 <track> Tag

The HTML <track> element is used as a child of the media elements—<audio> and <video>. It lets you specify timed text tracks (or time-based data), for example to automatically handle subtitles. The tracks are formatted in WebVTT format (.vtt files) — Web Video Text Tracks.

No content permitted inside the <track> tag as it is a void element. The start tag is mandatory for this element but there must be no closing tag. The parent of the <track> tag can be a media element, before any flow content.

The type of data that track adds to the media is set in the kind attribute, which can take values of subtitles, captions, descriptions, chapters or metadata. The element points to a source file containing timed text that the browser exposes when the user requests additional data.

Here are some examples of using this tag:

<video src="brave.webm">
  <track kind=subtitles src=brave.en.vtt srclang=en label="English">
  <track kind=captions src=brave.en.hoh.vtt srclang=en label="English for the Hard of Hearing">
  <track kind=subtitles src=brave.fr.vtt srclang=fr lang=fr label="Français">
  <track kind=subtitles src=brave.de.vtt srclang=de lang=de label="Deutsch">
</video>

Attributes

default

This attribute indicates that the track should be enabled unless the user’s preferences indicate that another track is more appropriate. This may only be used on one track element per media element.

kind

How the text track is meant to be used. If omitted the default kind is subtitles. If the attribute is not present, it will use the subtitles. If the attribute contains an invalid value, it will use metadata. (Versions of Chrome earlier than 52 treated an invalid value as subtitles.) The following keywords are allowed:

  • subtitles: Subtitles provide translation of content that cannot be understood by the viewer. For example dialogue or text that is not English in an English language film.

    Subtitles may contain additional content, usually extra background information. For example the text at the beginning of the Star Wars films, or the date, time, and location of a scene.

  • captions: Closed captions provide a transcription and possibly a translation of audio. It may include important non-verbal information such as music cues or sound effects. It may indicate the cue’s source (e.g. music, text, character). Suitable for users who are deaf or when the sound is muted.

  • descriptions: Textual description of the video content. Suitable for users who are blind or where the video cannot be seen.

  • chapters: Chapter titles are intended to be used when the user is navigating the media resource.
  • metadata: Tracks used by scripts. Not visible to the user.

label

A user-readable title of the text track which is used by the browser when listing available text tracks.

src

Address of the track (.vtt file). Must be a valid URL. This attribute must be defined.

srclang

Language of the track text data. It must be a valid BCP 47 language tag. If the kind attribute is set to subtitles, then srclang must be defined.

Further Reading

  1. Read more about the HTML <track> element on MDN.
  2. You can also read the HTML <track> tag reference on W3C.

Reader Comments

1. You can register or login to post a comment. Asking readers to register improves the quality of discussion.

2. As a registered user, you will also get to access features like choosing between a light and dark theme or anything else that we might implement in future.

Follow Us For Updates

FacebookTwitterGoogle+
Go To Top