Embed Youtube Iframe on Website with Auto Play

Embedding YouTube videos on your website can significantly enhance user engagement. One useful feature is the ability to set videos to autoplay when the page loads. It is important to note that for autoplay to work, the video must be muted. This is due to modern browser restrictions aimed at improving user experience by preventing unexpected audio playback.


Step-by-Step Guide

  1. Basic Embed Code: Start with the basic YouTube embed code. For example:

    1
    2
    3
    4
    5
        <iframe src="https://www.youtube.com/embed/1O0yazhqaxs"
                width="560"
                height="315"
                title="3 Second Video"
                frameborder="0"></iframe>

    https://jsfiddle.net/x4z73rjL/1/

  2. Add Autoplay and Mute Parameters: To enable autoplay, you must also mute the video. Modern browsers restrict autoplay unless the video is muted. Add the autoplay=1 and mute=1 parameters to the URL.
  3. Complete Embed Code: Combine these parameters to create the final embed code. Here’s the complete code to autoplay and mute the YouTube video:

    1
    2
    3
    4
    5
        <iframe src="https://www.youtube.com/embed/1O0yazhqaxs?autoplay=1&mute=1"
                width="560"
                height="315"
                title="3 Second Video"
                frameborder="0"></iframe>

    https://jsfiddle.net/x4z73rjL/2/


Example Breakdown

  • Video ID: 1O0yazhqaxs
  • Autoplay Parameter: autoplay=1 (enables autoplay)
  • Mute Parameter: mute=1 (mutes the video)

Final Embedded Video

Here is the full example of an embedded YouTube video that autoplays and is muted:

1
2
3
4
5
<iframe src="https://www.youtube.com/embed/1O0yazhqaxs?autoplay=1&mute=1"
        width="560"
        height="315"
        title="3 Second Video"
        frameborder="0"></iframe>

https://jsfiddle.net/fo3yg4w9/

This will embed the YouTube video on your webpage, and it will start playing automatically and be muted.


Additional Tips

  • Show Controls: If you want to keep the player controls visible, you can add controls=1 (this is the default setting, so it’s optional).

    1
        <iframe src="https://www.youtube.com/embed/1O0yazhqaxs?autoplay=1&mute=1&controls=1" width="560" height="315" title="3 Second Video" frameborder="0"></iframe>
  • Loop the Video: To make the video loop, add loop=1 and playlist with the video ID.

    1
    2
    3
    4
    5
        <iframe src="https://www.youtube.com/embed/1O0yazhqaxs?autoplay=1&mute=1&loop=1&playlist=1O0yazhqaxs"
                width="560"
                height="315"
                title="3 Second Video"
                frameborder="0"></iframe>

    https://jsfiddle.net/8h7vL5md/

By following these steps, you can easily embed YouTube videos on your website with autoplay and mute enabled, enhancing the viewing experience for your audience.

For more details, you can refer to Google’s Autoplay Policy and MDN Web Docs on Autoplay.


Hello, I am an enthusiastic Adobe Community Advisor and a seasoned Lead AEM Developer. I am currently serving as an AEM Technical Lead at MNPDigital.ca, bringing over a decade of extensive web engineering experience and more than eight years of practical AEM experience to the table. My goal is to give back to the AEM Full Stack Development community by sharing my wealth of knowledge with others. You can connect with me on LinkedIn.

Leave a Reply

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


Back To Top
xx1toto togel xx1 toto login xx1toto xx1toto link xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto xx1toto journalberitaterkini xx1toto xx1toto pasaran togel