Add Video to Site Background in HTML5



Add a button to play or pause the video. Then we have styled the video to a hundred percentage height and width so that it covers the entire background.

The following is the code snippet to set video as a site background in HTML5.

<video autoplay muted loop id = "myVideo">
   <source src = "demo.mp4" type = "video/mp4">
   Your browser does not support HTML5 video.
</video>

The following is to pause the video −

function display() {
   if (video.paused) {
      video.play();
      btn.innerHTML = "Pause the video!";
   } else {
      video.pause();
      btn.innerHTML = "Play";
   }
}
Updated on: 2020-06-24T13:58:52+05:30

403 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements