References

Beginner-friendly references for web development, with live, editable examples.

The HTML <track> label attribute

Attribute All modern browsers Updated
In short

The HTML label attribute on <track> names a text track in the player's captions menu. Examples include English and Español. When present it must not be empty, and two tracks with the same kind and language need different labels.

Overview

The label attribute on <track> names a text track for the people choosing it. Browsers use it when listing subtitle, caption and audio description tracks in their interface, so it is the text viewers see in the captions menu of a <video>.

The value must be a non-empty string when the attribute is present. The HTML Standard also forbids two tracks in the same media element that share a kind, a language and a label, so two English subtitle tracks, say the dialogue and a director's commentary, need different labels.

Leaving label off is allowed. The track's label then becomes an empty string, and the HTML Standard says the browser should generate a label from the track's other properties, such as its kind and language, which is a good reason to set one on every track.

In JavaScript the value is available as label on the track element and on the matching TextTrack in video.textTracks. A custom player can read each track's label to build its own captions menu and switch the track's mode when the viewer picks one.

Syntax

<track kind="subtitles" src="subs-es.vtt" srclang="es" label="Español">

Values

Value
A non-empty string, such as English or English (CC).

Example

Live example
<video id="v" src="https://codeshack.io/web/example.mp4" controls muted width="240">
  <track kind="subtitles" srclang="en" label="English" default src="data:text/vtt,WEBVTT%0A%0A00:00.000%20--%3E%2000:31.000%0AEnglish%20subtitles">
  <track kind="subtitles" srclang="es" label="Español" src="data:text/vtt,WEBVTT%0A%0A00:00.000%20--%3E%2000:31.000%0ASubt%C3%ADtulos%20en%20espa%C3%B1ol">
</video>
<p id="out"></p>
<p><small>Each track inlines its WebVTT text as a data: URL. A real page points src at a .vtt file.</small></p>
<script>
  const tracks = [...document.getElementById('v').textTracks];
  document.getElementById('out').textContent = 'Track labels: ' + tracks.map(t => t.label).join(', ');
</script>

Best practices

  • Write each label in the track's own language, such as Español or Deutsch, so viewers can spot their language in the menu.
  • Say what makes a track different when two share a language, for example English and English (CC) for subtitles and captions.
  • Give every track a label even though the attribute is optional, because an unlabeled track leaves the menu text to the browser.
  • Keep labels unique among tracks of the same kind and language, as the HTML Standard requires.

Accessibility

Clear labels help caption users pick the right track. When a video offers both subtitles and captions in one language, put the difference in the label, for example English (CC), so viewers who need sound effects and speaker names described can find the captions track.

Frequently asked questions

What does the label attribute do on a track element?
The track label attribute sets the name viewers see for a text track in the player's captions menu. It does not set the track's language or change its cues.
Is the label attribute required on the track element?
No, the track label attribute is optional. If you include it, the value cannot be empty, and without it each browser decides what the menu shows.
Can two track elements have the same label?
Two tracks can share a label only if they differ in kind or language. The HTML Standard forbids repeating the same kind, srclang and label combination within one media element.
How do I read a track's label in JavaScript?
Read the label property of the track element or of its TextTrack in video.textTracks. Both return the label attribute's value, or an empty string when it is missing.
What is the difference between the label and srclang attributes on a track?
The track label attribute is display text for people choosing a track. Srclang is a BCP 47 code for the track's language, and browsers can compare kind, language and label against a viewer's caption preferences.
Is the track label attribute related to the label element?
No, the track label attribute only titles a media text track. The <label> element is a separate feature that names a form control.