Converting videos to various formats can be challenging and time-consuming.
A more convenient approach is to embed YouTube videos directly on your web page for playback.
When you save or play a video on YouTube, it displays an ID (like tgbNymZ7vqY) that you can use to reference your video in HTML code.
To play your video on a web page, follow these steps:
<iframe>
element in your web page.src
attribute to point to the video URL.width
and height
attributes to specify the dimensions of the player.<iframe width=”420″ height=”315″ src=”https://www.youtube.com/embed/tgbNymZ7vqY”> </iframe> |
You can enable your video to start playing automatically when a user visits the page by adding autoplay=1 to the YouTube URL.
However, note that automatically starting a video can be intrusive for your visitors.
Note that in Chromium browsers, autoplay is generally restricted. However, muted autoplay is consistently permitted. |
To allow your video to start playing automatically (but muted), add mute=1 after autoplay=1 in the YouTube URL.
<iframe width=”420″ height=”315″ src=”https://www.youtube.com/embed/tgbNymZ7vqY?autoplay=1&mute=1″> </iframe> |
A comma-separated list of additional videos to play alongside the original URL.
To enable your video to loop indefinitely, add loop=1 to the YouTube URL.
<iframe width=”420″ height=”315″ src=”https://www.youtube.com/embed/tgbNymZ7vqY?playlist=tgbNymZ7vqY&loop=1″> </iframe> |
To hide controls in the video player, add controls=0 to the YouTube URL.
<iframe width=”420″ height=”315″ src=”https://www.youtube.com/embed/tgbNymZ7vqY?controls=0″> </iframe> |