default

The default attribute is a boolean used with the <track> element to indicate the default text track for audio or video content.

default attribute

The default attribute in HTML is a boolean used with the <track> element. It designates a specific text track to be displayed by default when the linked <audio> or <video> element begins playing. This feature is especially valuable for improving accessibility by automatically showing subtitles, captions, or other relevant text, helping users better comprehend the content.

Syntax

index.html
<track src="URL" default>

The default attribute doesn't require a value. Including the word "default" within the <track> tag is sufficient to enable it.

Example

Below is an example demonstrating how it can be used:

index.html
<video controls>
  <source src="video.mp4"  type="video/mp4">
  <track src="english_subtitles.vtt" kind="subtitles" srclang="en" label="English" default>
  <track src="spanish_subtitles.vtt" kind="subtitles" srclang="es" label="Spanish">
</video>
  • This example shows a <video> element with two subtitle tracks: one in English and another in Spanish. The default attribute is used on the English track, making it the default option. As the video plays, if no subtitle preference has been selected by the user, the English subtitles will appear by default.

Values

The default attribute is a boolean, meaning it does not require any associated values.

Applies To

The default attribute can be applied to the following HTML elements:

Example

index.html
<video controls>
  <source src="video.mp4" type="video/mp4">
  <track kind="subtitles" src="english.vtt" default label="English">
  <track kind="subtitles" src="french.vtt" label="French">
</video>

Conclusion

The default attribute in HTML improves accessibility by automatically showing a chosen text track, such as subtitles or captions, when a <video>, <audio> or <track> element starts playing. It enhances the user experience by removing the need to manually select a track. This attribute is particularly beneficial for content in multiple languages.