White Arrow icon
Back to all Elements

Background Video with Audio (using plyr.js)

An embed video with Mute/UnMute button using plyr.js plugin.

Using an Embed widget we add the html5 video tag and change our video source to the relevant video (I suggest using Google Cloud as a free hosting service for files).

* If you can decode to WEBM format as well, it will have better compatibility.

<video muted autoplay playsinline loop class="video">
 <source src="PLACE_YOUR_VIDEO_URL_HERE" type="video/mp4">
  <source src="PLACE_YOUR_VIDEO_URL_HERE" type="video/webm">
 Your browser does not support the video tag.
</video>

Copy

Now we add the plyr.js library and relevant code:

* this should be added on the page settings under "Before </body> tag"

<script src="https://cdn.plyr.io/3.7.2/plyr.js"></script>

<script>
 document.addEventListener('DOMContentLoaded', () => {
   const controls = [
     'mute',
   ];
   const player = Plyr.setup('.video', { controls, muted: true  });
 });
</script>

Copy

Lastly we need to style the video and the plyr.js buttons. We can do some of that with Webflow elements, by giving them the same classes as the plyr.js plugin uses, and then styling the elements in Webflow.

Other elements need some CSS:

* This can go anywhere, preferably in an Embed widget at the top of the canvas

<style>
 video {
   position: fixed;
   left: 0;
   right: 0;
   top: 0;
   bottom: 0;
   width: 100%;
   height: 100%;
   -webkit-object-fit: cover;
   -moz-object-fit: cover;
   -ms-object-fit: cover;
   object-fit: cover;
 }
 .plyr__control svg {
  width: 40px;
   height: 40px;
   margin-right: 10px;
 }
 .plyr__control span {
  display: none;
 }
</style>

Copy

Preview:

browser mockup
Share:
Heart icon

The videos Kurzgesagt channel creates are so beautifully animated, that I almost forget that I learn so much while watching them!

Might also interest you:

CMS Autocomplete

Cloneable
CMS
JavaScript

A short JavaScript code for transferring a CMS list into an autocomplete on an input field.

Read more
Blue arrow iconWhite Arrow icon

Auto get Current Year

Cloneable
Code
JavaScript

Automatically insert the current year to any element with the class of 'year'

Read more
Blue arrow iconWhite Arrow icon

Scroll Menu to Current Link

Cloneable
CMS
Code

Using JS to scroll a div (menu) to the current link inside.

Read more
Blue arrow iconWhite Arrow icon