HTML | DOM Video preload Property

The Video preload property in HTML’s Document Object Model (DOM) specifies whether a video should be loaded when the page loads. It accepts values like auto, metadata, and none to control preloading behavior.

The video preload attribute allows the author to portray to the browser the way the user experience of a website should be implemented.

Table of Content

  • Video preload property Values: 
  • Video preload property Return Value : 
  • Video preload Property Use Cases
  • Video preload Property Supported Browsers:

Video preload property Syntax: 

  • Return the preload property: 
     
videoObject.preload
  • Set the preload property: 
     
videoObject.preload = "auto|metadata|none"

Video preload property Values:

  • auto :It is used to specify that the browser should load the entire video when the page loads.
  • metadata :It is used to specify that the browser should load only metadata when the page loads.
  • none :It is used to specify that the browser should NOT load the video when the page loads.

Video preload property Return Value :

It returns a  string value, that represents what data should be preloaded (if any). Possible return values are “auto”, “metadata”, or “none”. See “Property Values” for what the values mean

Video preload property Example :

Here is the basic implementation of using Video preload Property.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        Video Preload Property
    </title>
</head>

<body style="text-align:center">

    <h1 style="color:green">
        w3wiki
    </h1>
    <h2 style="font-family: Impact">
        Video Preload Property
    </h2>
    <br>

    <video id="Test_Video" width="360" height="240" controls>
        <source src="samplevideo.mp4" type="video/mp4">

        <source src="movie.ogg" type="video/ogg">
    </video>



    <p>
        To return the value of the preload attribute,
        double click the "Return Preload Attribute" button.
    </p>



    <button onclick="My_Video()" 
            type="button">
        Return Preload Attribute
    </button>

    <p id="test"></p>



    <script>
        function My_Video() {
            let v = document.getElementById(
                "Test_Video").preload;
            document.getElementById("test").innerHTML = v;
        }
    </script>

</body>

</html>

Output: 


video preload property

HTML DOM Video preload Property Example Explanation :

  • In the above example we contains a video element with preload attribute set to auto and two video sources provided.
  • JavaScript function My_Video() retrieves and displays the value of the preload attribute on button click.
  • Inline CSS styles are applied for text alignment, color, and font family.
  • A button triggers the JavaScript function to show the preload attribute value.


HTML DOM Video preload Property Example :

In this example we includes video with preload property set by button click, enabling automatic loading of video resources.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        Video Preload Property
    </title>
</head>

<body style="text-align:center">

    <h1 style="color:green">
      w3wiki
    </h1>
    <h2 style="font-family: Impact">
      Video Preload Property
    </h2>
    <br>

    <video id="Test_Video"
           width="360" 
           height="240" 
           controls>
        <source src="samplevideo.mp4"
                type="video/mp4">
      
        <source src="movie.ogg"
                type="video/ogg">
    </video>

    

<p>To set the value of the preload attribute, 
      double click the "Set Preload Attribute" button.</p>



    <button ondblclick="My_Video()" 
            type="button">
      Set Preload Attribute
    </button>

    <p id="test"></p>



    <script>
        function My_Video() {
            var v = document.getElementById(
              "Test_Video").preload="auto";
            document.getElementById("test").innerHTML = v;
        }
    </script>

</body>

</html>

Output: 

videoPreload property

HTML DOM Video preload Property Example Explanation:

  • In the above-example we includes a video element with preload attribute set to “auto” and two video sources provided.
  • JavaScript function My_Video() sets the preload attribute to “auto” on double click of the button.
  • Inline CSS styles are applied for text alignment, color, and font family.
  • A button triggers the JavaScript function to set the preload attribute value.

HTML | DOM Video preload Property Use Cases

To preload a video when the page loads in HTML5, set the preload attribute of the video element to “auto”.

HTML | DOM Video preload Property Supported Browsers:

The browser supported by HTML | DOM Video preload Property are listed below: 
 

  • Google Chrome 3
  • Edge 12
  • Internet Explorer 9
  • Firefox 4
  • Opera
  • Apple Safari 3.1
     


Contact Us