HTML - poster Attribute



The HTML poster attribute is used to specify an image/poster for the video. It is displayed while the video is downloading or until the user clicks the play button.

If this attribute is not specified then nothing is displayed until the first frame is available, then the first frame is shown as a poster frame for the video.

Syntax

Following is the syntax of the HTML poster attribute

<video poster = "posterlocation/url"></video>

Where the poster location can be the location of your local image/poster or any URL.

Example

In the following example, we are using the HTML 'poster' attribute within the video element to specify an image/poster to the video until the user does not click on the play button.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML 'poster' attribute</title>
   <style>
      video {
         border: 3px solid rgb(86, 3, 3);
      }
   </style>
</head>
<body>
   <!--HTML 'poster' attribute-->
   <p>Example of the HTML 'poster' attribute</p>
   <video poster="Asset-2PPT_.png" width="400" height="250" controls>
      <source src="https://static.videezy.com/system/resources/previews/000/019/695/original/pointing-pink.mp4">
   </video>
</body>
</html>

When we run the above code, it will generate an output consisting of the video displayed on the webpage.

Example

Consider the another scenario, where we are going to use the poster attribute with the video element and specify the poster while the video is downloading.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML 'poster' attribute</title>
   <style>
      video {
         border: 3px solid rgb(86, 3, 3);
      }
   </style>
</head>
<body>
   <!--HTML 'poster' attribute-->
   <p>Example of the HTML 'poster' attribute</p>
   <video poster="Asset-2PPT_.png" width="400" height="250" controls>
      <source type="video/mp4" src="https://static.videezy.com/system/resources/previews/000/019/695/original/pointing-pink.mp4">
   </video>
</body>
</html>

On running the above code, the output window will pop up displaying the video onthe webpage.

Example

Let's look at the following example, where we are going to run the script using the poster attribute and also using the separate function to set and remove the poster.

<!DOCTYPE html>
<html lang="en">
<head>
   <title>HTML 'poster' attribute</title>
   <style>
      video {
         border: 5px solid rgb(123, 9, 200);
      }

      button {
         padding: 7px;
      }
   </style>
</head>
<body>
   <!--HTML 'poster' attribute-->
   <p>Example of the HTML 'poster' attribute</p>
   <video width="400" height="250" controls id='demo'>
      <source type="video/mp4" src="Fix battleground mobile india name is already taken problem solved - bgmi.mp4">
   </video>
   <br>
   <button onclick="Add()">Set poster</button>
   <button onclick="Remove()">Remove poster </button>
   <script>
      function Add() {
         document.getElementById('demo').poster = "download.png";
      }

      function Remove() {
         document.getElementById('demo').poster = "";
      }
   </script>
</body>
</html>

On executing the above script, the output window will pop up displaying the video along with a click buttons on the webpage. when the user tries to click the button the event gets triggered and perform respective action.

html_attributes_reference.htm
Advertisements