HTML YouTube Videos
The easiest way to play videos in HTML is to use YouTube.
Embedding a YouTube Video
To embed a YouTube video on your page, go to the YouTube video, click the "Share" button, then choose the "Embed" option. This will give you an <iframe> code that you can copy and paste into your HTML.
Example: Standard YouTube Embed
html
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>Autoplay and Mute
You can make your video autoplay by adding ?autoplay=1 to the YouTube URL. Note that most modern browsers will block autoplay unless the video is also muted. You can add &mute=1 to mute the video.
Example: Autoplay Muted
html
<iframe width="560" height="315"
src="https://www.youtube.com/embed/dQw4w9WgXcQ?autoplay=1&mute=1">
</iframe>Test Yourself with an Exercise
What HTML tag is commonly used to embed a YouTube video?