I have a client that wants videos published to his Webflow site to autoplay. Unfortunately the new YouTube element does not support linking to a collection (vote for this in the wishlist here)
What is my options? Can I use a script to get the old video element to autoplay or can I embed in other ways?
Edit: This lets me embed and autoplay, but it starts autoplay on page load and not on scroll in to view. It does not autoplay on iPhone neither.
Great!! Thanks @vincent
Follow up question: If I set the width to 100%, how can I set the height so that it matches the aspect ratio of the video?
Edit: Hm, iOS (only tested on iPhone) still do not allow autoplay
That may be a mobile browser thing that you can’t control. Do you have any example of autoplay yt videos on mobile?
Using a neat CSS trick, one of the weirdest rule of CSS, you can craft containers and control their aspect ratio. I made a landing page that is explaining how to:
I calculated that for a 16/9th ratio, you need to use width:50% and padding-bottom:28.125% .
Edit: for autoplay on mobile, search on google, you may need JS.
Hm, yes, looks like its hard to get autoplay to work on mobile devices.
That aspect ratio trick was nifty! But I have a bit of trouble getting it to work with a embedded video since you have to set both width and height in code. If I set width 100% on the video I have to set a height too… height does not respond to percentage value Is it possible to make a script that set the height to 16/9 of the width used in the browser window?
In other words; if I use width=100% on the video element the actual width will vary from user to user based on their screen resolution. Is it possible to measure the actual width of the video in the browser window and the set the height to a percentage value based on this?
Something like: Height = “56% of actual width”
autoplay block by google chrome
For embed code video this is very good libary (
4700 github stars - only set the parent width or 100%):
Write - If you need help with fitvidsjs & webflow.
@Sitron_Systems Yes!! the FitVids script looks like what I need! Hum, any pointers on Webflow implementation?
@vincent Definitely nicer with less complexity! Got the FitVids script to work in combination with the CMS-system (no autoplay on mobile), so will have to do for now, already passed the deadline on this project
Like @vincent thier is more solutions.
include assets (before body) under collection page (Webflow already include jquery)
<!-- fitvids.js -->
<!-- initialize fitvids.js -->
// Target Your video providers - for example youtube (or viemo and so on)
Add embed html youtube code to your page.
This is the trick of the
$jquery selector (select any iframe contain src with youtube)
Viemo? change to
$('iframe[src*="viemo"]') and so on.
Thats it. Done.
For other users. This trick is very usefull for
blog posts with youtube player inside the main article (Added by client).
Thanks for your time and help @Siton_Systems
Thanks for that because I’m gonna use it on a site of mine.
How would i loop the video? everything above is working great except at the end of the video the playlist opens.
Thank you so much in advance!!
@Michael_DeNardo If your using Vimeo I would have a lock at the Vimeo embed documentation. A lot of options there on what to show and not.
Hi Vincent, thanks for your explanation, written very exhaustively as always.
Unfortunately I don’t see the images for some reason.
Is this post of yours also available somewhere else?
Maybe on your Twitter?
Thank you for your commitment.