docs.rodeo

MDN Web Docs mirror

TextTrack

{{APIRef("WebVTT")}} 

The TextTrack interface of the WebVTT API represents a text track associated with a media element.

An object of this type owns the list of {{domxref("VTTCue")}}  objects that will be displayed over the video at various points.

TextTrack objects can be added to a {{domxref("HTMLVideoElement")}}  or {{domxref("HTMLAudioElement")}}  element using the {{domxref("HTMLMediaElement.addTextTrack()")}}  method, which has the same effect as adding text tracks declaratively using {{htmlelement("track")}}  elements inside a {{htmlelement("video")}}  or {{htmlelement("audio")}}  element. The TextTrack objects are stored in a {{domxref("TextTrackList")}} , which can be retrieved using the {{domxref("HTMLMediaElement.textTracks")}}  property.

{{InheritanceDiagram}} 

Instance properties

This interface also inherits properties from {{domxref("EventTarget")}} .

Instance methods

This interface also inherits methods from {{domxref("EventTarget")}} .

[!NOTE] The {{domxref("TextTrackCue")}}  interface is an abstract class used as the parent for other cue interfaces such as {{domxref("VTTCue")}} . Therefore, when adding or removing a cue you will be passing in one of the cue types that inherit from TextTrackCue.

Events

Example

The following example adds a new TextTrack to a video, then sets it to display using {{domxref("TextTrack.mode")}} .

let video = document.querySelector("video");
let track = video.addTextTrack("captions", "Captions", "en");
track.mode = "showing";

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN