JavaScript Answers

How to Embed an Auto-Playing YouTube Video in an Iframe?

Spread the love

Sometimes, we may want to embed an auto-playing YouTube video on our web page.

In this article, we’ll look at how to embed an auto-playing YouTube video in an iframe.

Embed Auto-playing YouTub Video

To embed an auto-playing YouTub video, we can write the following code:

<iframe width="420" height="345" src="" frameborder="0" allowfullscreen></iframe>

We add an iframe element with the width and height for the video.

In the src attribute, we have the YouTube video embed URL with the autoplay query parameter set to 1 to enable autoplay.

frameborder set to 0 removes the border around the iframe.

allowfullscreen lets us make the iframe full screen.


We can embed an auto-playing video in an iframe by setting the autoplay query parameter of the embed video URL to 1.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *