default
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
<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:
<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. Thedefault
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
<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.
controls
The controls attribute in HTML is a boolean that, when added to <video> or <audio> elements, ensures that the default playback controls are visible to the user.
height
The height attribute in HTML specifies the height of an element, using units like pixels or percentages. It plays a key role in preserving layout consistency, while also considering aspect ratios.