files/en-us/web/api/videotrack/index.md
{{APIRef("HTML DOM")}}
The VideoTrack interface represents a single video track from a {{HTMLElement("video")}} element.
The most common use for accessing a VideoTrack object is to toggle its {{domxref("VideoTrack.selected", "selected")}} property in order to make it the active video track for its {{HTMLElement("video")}} element.
true for one track while another track is active will make that other track inactive.kind of "main".kind is "sign" might have a label of "A sign-language interpretation". This string is empty if no label is provided."en-US" or "pt-BR".To get a VideoTrack for a given media element, use the element's {{domxref("HTMLMediaElement.videoTracks", "videoTracks")}} property, which returns a {{domxref("VideoTrackList")}} object from which you can get the individual tracks contained in the media:
const el = document.querySelector("video");
const tracks = el.videoTracks;
You can then access the media's individual tracks using either array syntax or functions such as {{jsxref("Array.forEach", "forEach()")}}.
This first example gets the first video track on the media:
const firstTrack = tracks[0];
The next example scans through all of the media's video tracks, activating the first video track that is in the user's preferred language (taken from a variable userLanguage).
for (const track of tracks) {
if (track.language === userLanguage) {
track.selected = true;
break;
}
}
The {{domxref("VideoTrack.language", "language")}} is specified as a valid {{glossary("BCP 47 language tag")}}, for example "en-US" for US English.
{{Specifications}}
{{Compat}}