HTML YouTube Videos
HTML YouTube Videos
You can embed YouTube videos directly into your web page using the <iframe> tag. This allows visitors to watch videos without leaving your site.
Basic Syntax
-
Replace
VIDEO_IDwith the unique ID of the YouTube video. -
widthandheight→ Video size on your page. -
allowfullscreen→ Allows full-screen mode. -
allow→ Permissions for autoplay, clipboard, and other features.
Example HTML Page with YouTube Video
Responsive YouTube Video
To make the embedded video responsive on all devices:
-
padding-bottom: 56.25%→ Maintains 16:9 aspect ratio. -
width: 100%; height: 100%→ Makes video scale with screen size.
Key Points
-
<iframe>is the standard way to embed YouTube videos. -
Always use responsive containers for mobile-friendly pages.
-
You can control autoplay, controls, loop, and start time using YouTube URL parameters:
-
?autoplay=1→ Auto-start video -
?start=30→ Start at 30 seconds -
?controls=0→ Hide controls
-
