HTML Youtube


🔹 What is YouTube Embedding?

YouTube embedding allows you to display and play a YouTube video directly inside your web page using the <iframe> tag. This method is commonly used to show tutorials, product videos, and more.


🔹 Basic Syntax
<iframe width="560" height="315"
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player"
frameborder="0"
allowfullscreen></iframe>

Replace VIDEO_ID with the actual YouTube video ID.


🔹 Example: Embed a YouTube Video
<iframe width="560" height="315" 
src="https://www.youtube.com/embed/tgbNymZ7vqY" 
title="YouTube Video Player" frameborder="0" 
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" 
allowfullscreen></iframe>

🔹 How to Get the YouTube Embed Code

  1. Go to the YouTube video.

  2. Click the Share button.

  3. Click on Embed.

  4. Copy the <iframe> code provided.

  5. Paste it into your HTML page.


🔹 Customizing the Embed

  • Width and Height: Control the size.

  • allowfullscreen: Enables full-screen mode.

  • Add Parameters:

    • ?autoplay=1: Auto-plays the video.

    • ?controls=0: Hides controls.

    • ?loop=1&playlist=VIDEO_ID: Loops the video.

Example with Autoplay and Loop:

<iframe width="560" height="315" 
src="https://www.youtube.com/embed/tgbNymZ7vqY?autoplay=1&loop=1&playlist=tgbNymZ7vqY" 
frameborder="0" allowfullscreen></iframe>

🔹 Making the YouTube Video Responsive

Use a wrapper with CSS to make it scale on all devices:

<style>
.responsive-video {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
}
.responsive-video iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
</style>

<div class="responsive-video">
  <iframe src="https://www.youtube.com/embed/tgbNymZ7vqY" frameborder="0" allowfullscreen></iframe>
</div>

Practice Questions

Q1. Embed a YouTube video using the <iframe> tag.

Q2. Set a video size to 800px width and 450px height.

Q3. Enable fullscreen for the video.

Q4. Make the video autoplay on page load.

Q5. Remove controls from the video player.

Q6. Embed a YouTube video with looping enabled.

Q7. Make the embedded video responsive using CSS.

Q8. Display multiple YouTube videos on one page.

Q9. Use a YouTube embed code copied from the YouTube site.

Q10. Use the title attribute to describe the embedded video.


HTML Youtube Quiz

Q1: Which HTML tag is used to embed a YouTube video?

A. <video>
B. <object>
C. <iframe>
D. <embed>

Q2: What attribute allows fullscreen playback of a YouTube video?

A. fullscreen
B. showfullscreen
C. allowfullscreen
D. maxscreen

Q3: What YouTube feature adds the video player’s ability to autoplay?

A. ?autoplay=1
B. autostart=yes
C. start=true
D. autoplay=true

Q4: How do you loop a YouTube video in embed?

A. ?loop=1
B. loop="yes"
C. ?repeat=1
D. autoplay=loop

Q5: Where can you find the embed code for a YouTube video?

A. Under the video > Download
B. Right-click the video
C. Share > Embed
D. Tools > Options

Q6: What does frameborder="0" do in an <iframe>?

A. Disables autoplay
B. Adds a border to the frame
C. Removes the border
D. Enables fullscreen

Q7: What tag wraps a responsive YouTube video layout using CSS?

A. <container>
B. <video-box>
C. <responsive>
D. <div>

Q8: What parameter hides the YouTube player controls?

A. ?display=off
B. ?hide=1
C. ?controls=0
D. ?nobuttons=true

Q9: Which CSS technique is used to make YouTube embeds responsive?

A. Flexbox
B. Grid
C. Padding-bottom with relative positioning
D. Z-index layering

Q10: Which attribute is used to describe the iframe content for accessibility?

A. desc
B. label
C. title
D. name

Go Back Top