The read-only TextTrackList property length returns the number of entries in the TextTrackList, each of which is a TextTrack representing one track in the media element. A value of 0 indicates that there are no text tracks in the media.


var trackCount = TextTrackList.length;


A number indicating how many text tracks are included in the TextTrackList. Each track can be accessed by treating the TextTrackList as an array of objects of type TextTrack.


This snippet gets the number of text tracks in the first media element found in the DOM by querySelector().

var mediaElem = document.querySelector("video, audio");
var numTextTracks = 0;

if (mediaElem.textTracks) {
  numTextTracks = mediaElem.textTracks.length;

Note that this sample checks to be sure HTMLMediaElement.textTracks is defined, to avoid failing on browsers without support for TextTrack.


Specification Status Comment
HTML Living Standard
The definition of 'TextTrackList: length' in that specification.
Living Standard  

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
lengthChrome Full support 44Edge Full support ≤18Firefox Full support YesIE ? Opera Full support 31Safari Full support 10WebView Android Full support 44Chrome Android Full support 44Firefox Android ? Opera Android Full support 32Safari iOS ? Samsung Internet Android Full support 4.0


Full support  
Full support
Compatibility unknown  
Compatibility unknown