Video textTracks Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video


The textTracks property returns a TextTrackList object, which represents the available text tracks for the video.

Each available text track is represented by a TextTrack Object.

Return Value

Type Description
TextTrackList Object Represents the available text tracks for the the video.
TextTrack Object Represents a text track.

TextioTrackList Object:

  • length - get the number of text tracks available in the video
  • [index] - get TextTrack object by index

The first available TextTrack object is index 0

TextTrack Object Properties:

  • kind - get the type of the text track (possible value: "subtitles", "caption", "descriptions", "chapters", or "metadata")
  • label - get the label
  • language - get the language
  • mode - get or set if the track is active ("disabled"|"hidden"|"showing")
  • cues - get a list of cues as a TextTrackCueList object
  • activeCues - get the currently active text track cues as a TextTrackCueList object
  • addCue(cue) - add a cue to the list of cues
  • removeCue(cue) - remove a cue from the list of cues

The following code shows how to get the number of available text tracks:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  <track src="demo_sub.vtt">
  Your browser does not support the video tag.
</video>/*from   ww  w.ja va 2s.c  o  m*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("myVideo").textTracks.length;
    document.getElementById("demo").innerHTML = x;


Related Tutorials