References

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

The HTML default attribute

Attribute All modern browsers Updated
In short

The HTML default attribute turns a <track> on unless the viewer's settings pick another. It is a boolean attribute, and a media element may have only one default among its subtitles and captions tracks.

Overview

The default attribute tells the browser which text track to enable when nothing else decides. It is a boolean attribute of the <track> element, and the HTML Standard defines it as enabling the track unless the user's preferences point to a more appropriate one.

Without it, a track stays disabled unless the viewer's preferences select it. A disabled track is not even fetched, so captions stay off until the viewer picks them from the menu or a script changes the track's mode. With default on a subtitles or captions track, automatic track selection sets that track to showing, as long as no track in that group is already showing and the viewer's preferences do not pick another one.

The limits depend on the kind. One default is allowed among subtitles and captions together, one among descriptions and one among chapters, while any number of metadata tracks may carry it. A default chapters or metadata track is set to hidden rather than showing, so its cues load for scripts without being drawn.

Safari adds one requirement of its own. MDN notes that when you build your own video controls, Safari only shows subtitle cues if the track has the default attribute.

Syntax

<track kind="captions" src="captions-en.vtt" srclang="en" label="English (CC)" default>

Values

Value
A boolean attribute: present or absent.

Example

Live example
<video id="v" src="https://codeshack.io/web/example.mp4" controls muted width="240">
  <track kind="subtitles" srclang="fr" label="Français" src="data:text/vtt,WEBVTT%0A%0A00:00.000%20--%3E%2000:31.000%0ASous-titres%20en%20fran%C3%A7ais">
  <track kind="captions" srclang="en" label="English (CC)" default src="data:text/vtt,WEBVTT%0A%0A00:00.000%20--%3E%2000:31.000%0A(music)%20The%20default%20track%20is%20on">
</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 list = document.getElementById('v').textTracks;
  const show = () => {
    document.getElementById('out').textContent = [...list].map(t => t.label + ' is ' + t.mode).join(', ');
  };
  list.addEventListener('change', show);
  show();
</script>

Best practices

  • Put default on the captions track in the video's main language when the dialogue matters, so viewers who watch with the sound off still get the words.
  • Use it on only one subtitles or captions track per media element, as the HTML Standard requires.
  • Load a metadata track your script depends on by setting its mode to hidden, which fetches the cues without drawing them.
  • Include default on the first visible track when you build custom controls, since MDN notes Safari needs it to show subtitle cues.
  • Treat default as a fallback, not a lock. The viewer's caption preferences are checked first, and the player menu still lets viewers switch.

Accessibility

A default captions track shows spoken content to viewers who cannot hear the audio. It also helps anyone watching with the sound off, and it does not override anyone's settings, because the browser checks the viewer's caption preferences before it falls back to the default track.

Frequently asked questions

What does the default attribute do on a track element?
The default attribute turns a text track on when the viewer's settings do not choose another one. Without it, a track stays disabled unless the viewer's settings, the captions menu or a script turn it on.
Why are my captions not showing until I pick them from the menu?
Tracks without the default attribute start disabled and are not even loaded. Add default to the captions track, or set its mode to showing in JavaScript.
Can more than one track have the default attribute?
Only one subtitles or captions track per media element may have the default attribute. Descriptions and chapters tracks allow one each, and metadata tracks have no limit.
Does the default attribute override the viewer's caption settings?
No, the track default attribute is only a fallback. A browser that knows the viewer wants French captions can enable the French track instead.
How do I turn on a track with JavaScript instead of the default attribute?
Set the TextTrack's mode property to showing, as in video.textTracks[0].mode = 'showing'. The hidden mode loads cues without drawing them, which is what the default attribute does for metadata tracks.
Why do my subtitles not appear in Safari with custom controls?
MDN notes that Safari shows subtitle cues in a custom player only when the track has the default attribute. Add default to the track that should be visible first.