HTML - default Attribute



HTML default attribute used to indicate that a track should be enabled unless the user's preferences indicate that another track is more appropriate.

The default can only be used on one 'track' element per media element. If multiple tracks are marked as default, the first one will be used. You can use the default attribute with JavaScript to check whether this attribute present in the media element or not. If present returns true, otherwise it's false.

Syntax

<track default>

Applies On

Below listed element allow using of the HTML default attribute

Element Description
<track> HTML <track> tag is used to define the time-based text tracks for a media file.

Examples of HTML default Attribute

Bellow examples will illustrate the HTML default attribute, where and how we should use this attribute!

Set default subtitle for Video

In the following example, we are going to use the default attribute with the track element to mention default subtitle for video.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML 'default' attribute</title>
   <style>
      video {
         border: 5px solid black;
         border-radius: 10px;
      }
   </style>
</head>
<body>
   <!--HTML 'default' attribute-->
   <h3>
      Example of the HTML 'default' attribute
   </h3>
   <video width="300" controls>
      <source src=
"https://samplelib.com/lib/preview/mp4/sample-20s.mp4">
      <track srclang="subtitles" label="english" default>
      <track srclang="subtitles" label="Hindi" >
   </video>
   <p>
      This is video with two subtitles, 
      with english being default 
   </p>
</body>
</html>

Set default attribute for audio

Considering the another scenario, where we are going to use the default attribute with the track element of the audio.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML 'default' attribute</title>
   <style>
      audio {
         border: 5px solid black;
         border-radius: 10px;
      }
   </style>
</head>
<body>
   <!--HTML 'default' attribute-->
   <h3>
      Example of the HTML 'default' attribute
   </h3>
   <audio controls>
      <source src=
"https://samplelib.com/lib/preview/mp3/sample-6s.mp3">
      <track srclang="subtitles" default>
      <track srclang="subtitles" >
   </audio>
   <p>
      Here the first subtitle is being default.
   </p>
</body>
</html>

Supported Browsers

Attribute Chrome Edge Firefox Safari Opera
default Yes 18.0 Yes 10.0 Yes 31.0 Yes 6.0 Yes 15.0
html_attributes_reference.htm
Advertisements