HTMLMediaElement: textTracks property - Web APIs | MDN

Value

A TextTrackList object representing the list of text tracks included in the media element. The list of tracks can be accessed using textTracks[n] to get the n-th text track from the object's list of text tracks, or using the textTracks.getTrackById() method.

Each track is represented by a TextTrack object which provides information about the track.

Examples

We start with a <video> that has several <track> children

html

<video controls>
  <source src="/shared-assets/videos/sintel-short.webm" type="video/webm" />
  <source src="/shared-assets/videos/sintel-short.mp4" type="video/mp4" />
  <track
    kind="subtitles"
    src="/shared-assets/misc/sintel-en.vtt"
    srclang="en"
    label="English" />
  <track
    kind="subtitles"
    src="/shared-assets/misc/sintel-de.vtt"
    srclang="de"
    label="Deutsch" />
  <track
    kind="subtitles"
    src="/shared-assets/misc/sintel-es.vtt"
    srclang="es"
    label="EspaƱol" />
</video>

The HTMLMediaElement.textTracks returns a TextTrackList through which we can iterate. Here we set all three tracks to show simultaneously.

js

const tracks = document.querySelector("video").textTracks;

for (const track of tracks) {
  track.mode = "showing";
}

Specifications

Specification
HTML
# dom-media-texttracks-dev

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.