Embedding YouTube videos on your website is a common practice, but sometimes you may want the video to loop continuously. Fortunately, YouTube provides an easy way to set up looping for embedded videos.
Basic Embed Code
Start with the basic YouTube embed code (without loop). 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> |
Step 1: add Required “loop” Parameter
To enable looping, you need to add loop=1 to the URL parameters.
Step 2: add Required “playlist” Parameter
You also need to include the playlist parameter with the video ID to ensure the video loops. The playlist parameter should have the same video ID as the video you want to loop.
Complete Embed Code
Combine these parameters to create the final embed code. Here’s the complete code to loop the YouTube video:
1 2 3 4 5 | <iframe src="https://www.youtube.com/embed/1O0yazhqaxs?loop=1&fs=0&playlist=1O0yazhqaxs" width="560" height="315" title="3 Second Video" frameborder="0"></iframe> |
Example: https://jsfiddle.net/x4z73rjL/
Example Breakdown
- Video ID: 1O0yazhqaxs
- Loop Parameter: loop=1 (enables looping)
- Playlist Parameter: playlist=1O0yazhqaxs (repeats the same video)
Final Embedded Video
Here is the full example of an embedded YouTube video that loops continuously:
1 2 3 4 5 | <iframe src="https://www.youtube.com/embed/1O0yazhqaxs?loop=1&fs=0&playlist=1O0yazhqaxs" width="560" height="315" title="3 Second Video" frameborder="0"></iframe> |
Example: https://jsfiddle.net/x4z73rjL/
This will embed the YouTube video on your webpage, and it will loop automatically once it reaches the end.
Additional Tips
- Autoplay: If you want the video to start playing automatically when the page loads, you can add the autoplay=1 parameter to the URL.
1<iframe src="https://www.youtube.com/embed/1O0yazhqaxs?loop=1&fs=0&playlist=1O0yazhqaxs&autoplay=1" width="560" height="315" title="3 Second Video" frameborder="0"></iframe>
- Remove Controls: To hide the player controls, add controls=0 to the URL parameters.
1<iframe src="https://www.youtube.com/embed/1O0yazhqaxs?loop=1&fs=0&playlist=1O0yazhqaxs&controls=0" width="560" height="315" title="3 Second Video" frameborder="0"></iframe>
By following these steps, you can easily loop embedded YouTube videos on your website, providing a seamless viewing experience for your audience.
