How can I add a background video to my Webflow site using custom code?

TL;DR
  • Optimize your video in MP4 format and upload it to a hosting service. 
  • Add HTML custom code with your video URL in the "Before </body>" section of Webflow Page Settings.
  • Apply CSS for full-screen background video in the Site Settings "Custom Code" section.
  • Publish your site and test across devices for proper display and performance.

Adding a background video to your Webflow site using custom code can enhance the visual appeal of your site. Follow these steps to implement it:

1. Prepare Your Video File

  • Ensure your video is optimized for web use, ideally in MP4 format.
  • Upload your video to a reliable hosting service like Google DriveDropbox, or a direct-link CDN that allows video embedding.

2. Add Custom Code to Webflow

  • Go to the Designer of your Webflow project.
  • Open the Page Settings where you wish to add the video.
  • In the "Before </body>" Custom Code section, insert the following HTML snippet with your video URL:

  ```

  <video autoplay muted loop id="background-video">

    <source src="YOURVIDEOURL.mp4" type="video/mp4">

    Your browser does not support the video tag.

  </video>

  ```

  • Replace YOURVIDEOURL.mp4 with your actual video URL.

  

3. Style Your Video with Custom CSS

  • Add Custom CSS to ensure the video covers the background properly. Insert this CSS in the "Custom Code" section under Site Settings:

  ```

  #background-video {

    position: fixed;

    right: 0;

    bottom: 0;

    min-width: 100%; 

    min-height: 100%;

    z-index: -1;

  }

  ```

  • This CSS makes the video fixed as a full-screen background with no overflow.

4. Publish and Test

  • Publish your site to verify that the video displays correctly in the background.
  • Test your site on multiple devices and browsers to ensure compatibility and performance.

Summary

To add a background video using custom code, upload your video to a hosting service, integrate the video using custom HTML in your page settings, style it with CSS ensuring it covers the background as needed, and then publish and test it on different devices.

Rate this answer

Other Webflow Questions