HTML default Attribute
The HTML default attribute is a Boolean attribute used with the <track> element. It indicates that a text track should be enabled when the user's preferences do not indicate that another available track is more appropriate.
Syntax
The default attribute is placed on a <track> element to identify a text track that should initially be enabled when another track is not more appropriate for the user.
<video controls>
<source src="video.mp4" type="video/mp4">
<track src="captions.vtt" kind="captions" srclang="en" label="English" default>
</video>
In this example, the English captions are identified as the default captions track.
Boolean Attribute
The default attribute is a Boolean attribute. Its presence represents true, and its absence represents false.
<track src="captions.vtt" kind="captions" srclang="en" default>
Writing default="false" does not disable the attribute. Because the attribute is present, it is still considered true.
<!-- The default attribute is still enabled -->
<track src="captions.vtt" kind="captions" srclang="en" default="false">
To prevent the track from being identified as a default track, omit the default attribute entirely.
Elements That Use the default Attribute
The default attribute applies to the <track> element.
| Element | Description |
|---|---|
<track> |
Indicates that the text track should be enabled when the user's preferences do not make another track more appropriate. |
Default Track Selection
The <track> element provides timed text or other time-based information for an <audio> or <video> element. The default attribute helps the browser determine which track should initially be enabled.
<video controls>
<source src="video.mp4" type="video/mp4">
<track src="captions-en.vtt"
kind="captions"
srclang="en"
label="English"
default>
</video>
The browser can use the default track when the user's language, accessibility, or other preferences do not indicate that a different track is more suitable.
Using Multiple Tracks
A media element can provide multiple text tracks, such as captions or subtitles in different languages.
<video controls>
<source src="video.mp4" type="video/mp4">
<track src="captions-en.vtt"
kind="captions"
srclang="en"
label="English"
default>
<track src="captions-es.vtt"
kind="captions"
srclang="es"
label="Spanish">
</video>
In this example, the English captions are marked as the default. Users can still select another available track through the media controls when the browser provides that option.
User Preferences
The default attribute does not guarantee that its track will always be used. A browser can select another track when the user's preferences indicate that another available track is more appropriate.
This allows browser and user preferences to take precedence over the author's default selection when appropriate.
Common Mistakes
Do not use default="false" to turn the attribute off. The default attribute is Boolean, so its presence enables it regardless of the text assigned to it.
Do not assume that marking a track as default forces every browser to display that track. User preferences can affect which track is selected.
When providing multiple tracks of the same kind, avoid marking multiple competing tracks as default. Select the track that should normally be enabled and allow the user or browser to choose another when appropriate.
Browser Support
Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.
The default attribute on the <track> element is widely supported in current core browsers.
Checking Browser Support
For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.
Try the default Attribute
The example uses the default attribute to identify the English captions track as the preferred track for a video.
Summary
The HTML default attribute is a Boolean attribute used with the <track> element. It identifies a text track that should be enabled when the user's preferences do not indicate that another track is more appropriate. Because it is a Boolean attribute, its presence represents true and its absence represents false.
