HTML YouTube Videos
Add a YouTube Video to a Webpage
The easiest way to play videos in a webpage, is to use YouTube.
To play a YouTube video on a webpage, do the following:
- Upload the video you want to embed on your webpage on YouTube
- YouTube will display a video ID when you save (or play) a video
- Copy the video ID of the video
- Put an
<iframe>element on your webpage - Let the
srcattribute point to the URL of the video (with the ID) - Use the
widthandheightattributes to specify the dimension of the player - Add any other parameters to the URL (see below)
Example
<iframe width="420" height="315"
src="https://www.youtube.com/embed/tgbNymZ7vqY">
</iframe>
Try it Yourself »
How to Get the YouTube Video ID?
- Open the YouTube video you want
- Right click on the video, and select "Stats for nerds"
- The first value in the box is the video ID
YouTube Autoplay + Mute
You can let your video start playing automatically when a user visits the
page, by adding autoplay=1 to the YouTube URL.
However, automatically starting a video might be annoying for your visitors!
So, add mute=1 after
autoplay=1 to let your video start playing automatically (but muted).
Example
<iframe width="420" height="315"
src="https://www.youtube.com/embed/tgbNymZ7vqY?autoplay=1&mute=1">
</iframe>
Try it Yourself »
YouTube Playlist
A comma separated list of videos to play (in addition to the original URL).
YouTube Loop
Add playlist=videoID and loop=1 to let your video loop forever.
loop=0 (default) - The video will play only once.
loop=1 - The video will loop (forever).
YouTube - Loop forever
<iframe width="420" height="315"
src="https://www.youtube.com/embed/tgbNymZ7vqY?playlist=tgbNymZ7vqY&loop=1">
</iframe>
Try it Yourself »
YouTube Controls
Add controls=0 to NOT display controls in the
video player.
controls=0 - Player controls does not display.
controls=1 (default) - Player controls is displayed.
YouTube - Controls
<iframe width="420" height="315"
src="https://www.youtube.com/embed/tgbNymZ7vqY?controls=0">
</iframe>
Try it Yourself »