HTML <track> id Attribute

An id on a <track> tag assigns an identifier to the text track.

The identifier must be unique across the page.



An id attribute on a <track> element.

<video controls="controls" width="320" height="176">
  <source src="/media/godfather.mp4" type="video/mp4" />
  <source src="/media/godfather.ogg" type="video/ogg" />
  <track id="godfather-track" src="/media/" kind="subtitles" srclang="es" label="Spanish" />

Using id

The id attribute assigns an identifier to the <track> element.

The id allows JavaScript to easily access the <track> element.

It is also used to point to a specific id selector in a style sheet.

Tip:  id is a global attribute that can be applied to any HTML element.


<track id="identifier" />



Value Description
identifier A unique alphanumeric string. The id value must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.).

More Examples

A <track> tag with a unique id attribute.
Clicking the button displays the src value on the track element.

<video width="320" height="240" controls>
  <source src="/media/movie.mp4" type="video/mp4">
  <source src="/media/movie.ogg" type="video/ogg">
  <track id="mytrack" src="/media/" kind="subtitles" srclang="es" label="Spanish" />

<br /><br />
<button onclick="show();">Show track src</button>

  let show = () => {
    let element = document.getElementById("mytrack");
    alert("Src = " + element.src);

Code explanation

The id attribute assigns a unique identifier for the <track>.

Clicking the button calls JavaScript which locates the <track> using the id.

Finally, the src value of the track is displayed in an alert box.

Browser support

Here is when id support started for each browser:

18.0 Mar 2012
31.0 Jul 2014
10.0 Sep 2012
15.0 Jul 2015
6.0 Jul 2012

You may also like

 Back to <track>

Author: Jack Poorte
Published: Jun 20 2021
Last Reviewed: Sep 30 2023

What's your favorite/least favorite part of Dofactory?