How to embed an autoplaying YouTube video in an iframe?


I am trying to embed the new iframe version of a YouTube video and get it to auto play.

As far as I can tell, there is no way of doing this by amending flags to the URL. Is there a way to do it by using JavaScript & the API?

This question is tagged with javascript html iframe youtube youtube-api

~ Asked on 2011-09-02 09:50:31

The Best Answer is


This works in Chrome but not Firefox 3.6 (warning: RickRoll video):

<iframe width="420" height="345" src="" 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.

~ Answered on 2011-09-02 16:31:34


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="" allow='autoplay'></iframe>

~ Answered on 2018-07-04 18:32:19

Most Viewed Questions: