Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

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.

Example

#

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/godfather.srt" kind="subtitles" srclang="es" label="Spanish" />
</video>

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.


Syntax

<track id="identifier" />

Values

#

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/movie.srt" kind="subtitles" srclang="es" label="Spanish" />
</video>

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

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

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:

Chrome
18.0 Mar 2012
Firefox
31.0 Jul 2014
IE/Edge
10.0 Sep 2012
Opera
15.0 Jul 2015
Safari
6.0 Jul 2012

You may also like

 Back to <track>
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

Guides