How to embed an autoplaying YouTube video in an iframe?
August 2018 I didn't find a working example on the iframe implementation. Other questions were related to Chrome only, which gave it away a little.
You'll have to mute sound mute=1
in order to autoplay on Chrome. FF and IE seem to be working just fine using autoplay=1
as parameter.
<iframe src="//www.youtube.com/embed/{{YOUTUBE-ID}}?autoplay=1&mute=1" name="youtube embed" allow="autoplay; encrypted-media" allowfullscreen></iframe>
Since April 2018, Google made some changes to the Autoplay Policy. You not only need to add the autoplay=1
as a query param, but also add allow='autoplay'
as an iframe's attribute
So you will have to do something like this:
<iframe src="https://www.youtube.com/embed/VIDEO_ID?autoplay=1" allow='autoplay'></iframe>
The embedded code of youtube has autoplay off by default. Simply add autoplay=1
at the end of "src" attribute. For example:
<iframe src="http://www.youtube.com/embed/xzvScRnF6MU?autoplay=1" width="960" height="447" frameborder="0" allowfullscreen></iframe>
This works in Chrome but not Firefox 3.6 (warning: RickRoll video):
<iframe width="420" height="345" src="http://www.youtube.com/embed/oHg5SJYRHA0?autoplay=1" frameborder="0" allowfullscreen></iframe>
The JavaScript API for iframe embeds exists, but is still posted as an experimental feature.
UPDATE: The iframe API is now fully supported and "Creating YT.Player objects - Example 2" shows how to set "autoplay" in JavaScript.