How can I make a background video autoplay on iPhone/Safari in Webflow?

Published on
September 22, 2023

To make a background video autoplay on iPhone/Safari in Webflow, you need to use a workaround due to autoplay restrictions imposed by Apple in Safari for iOS devices. Here's a step-by-step guide on how to achieve this:

  1. Choose a suitable video format: Start by ensuring that your video is in a format that is compatible with Safari on iOS devices. The recommended format is MP4 with H.264 video codec and AAC audio codec.

  2. Upload your video: In your Webflow project, go to the Assets panel and upload your video file. Once uploaded, make a note of the URL of the video file.

  3. Add a background video element: Drag and drop a Video element onto your page where you want the background video to appear.

  4. Set the video source: With the Video element selected, locate the Video properties in the right sidebar. In the Video Source field, paste the URL of your video file.

  5. Disable autoplay: By default, Webflow sets the autoplay attribute to "on" for background videos. However, this doesn't work on iOS devices. To disable autoplay, click on the gear icon in the Video properties, and deselect the "Autoplay" option.

  6. Add a play button: To give users the option to manually play the video, you can place a play button over the video. You can use a transparent image with an interaction set to play the video on click.

  7. Add Safari-specific autoplay code: Go to the Custom Code tab in your project settings. In the Head Code section, add the following code:

<script>    document.addEventListener('DOMContentLoaded', function () {        var video = document.getElementsByTagName('video')[0];        video.muted = true;        video.play();    });</script>

This code targets the first video element on the page and mutes it before triggering the play action. The video should now automatically start playing when the page loads in Safari on iOS devices.

  1. Test on iOS: Preview your Webflow project and test the background video on an iPhone or iPad in Safari to ensure that it starts autoplaying as expected.

By following these steps, you can overcome the autoplay restrictions in Safari on iOS devices and make your background video autoplay in Webflow.

Additional Questions:

  1. How can I make a background video autoplay in Webflow?
  2. What video formats work best for background videos in Webflow?
  3. How do I add a play button overlay to a background video in Webflow?