HTML Iframes - YouTube Video Parameter for Autoplay
When a YouTube video is embedded into an HTML page using an iframe, it is embedded using the default parameters.
Autoplay is one such parameter, which will make the video autoplay itself upon page load automatically.
By default, embedded YouTube video is not going to play automatically, and the user has to click the play button to play a video.
<iframe src="https://www.youtube.com/embed/5UMde7utfCI" title="YouTube Video" width="800" height="450"></iframe>
However, we can make video autoplay itself after the page has loaded by setting the below parameter to the source URL.
- autoplay=1 (enables autoplay)
- autoplay=0 (default, disable autoplay)
<iframe src="https://www.youtube.com/embed/5UMde7utfCI?autoplay=1" title="YouTube Video" width="800" height="450"></iframe>
Example
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h1>HTML Iframes YouTube Video Parameter for Autoplay</h1>
<h2>Default Parameters (without autoplay)</h2>
<iframe src="https://www.youtube.com/embed/5UMde7utfCI" title="YouTube Video" width="800" height="450"></iframe>
<h2>Autoplay Parameter (Enabled)</h2>
<iframe src="https://www.youtube.com/embed/5UMde7utfCI?autoplay=1" title="YouTube Video" width="800" height="450"></iframe>
<h2>Autoplay Parameter (Disabled)</h2>
<iframe src="https://www.youtube.com/embed/5UMde7utfCI?autoplay=0" title="YouTube Video" width="800" height="450"></iframe>
</body>
</html>
Overall
We now know how to embed a YouTube video into an HTML page and make it autoplay itself upon page load.