Youtube in HTML
?? Embedding YouTube Videos in HTML
You can easily embed YouTube videos on your webpage using the <iframe> tag.
Basic YouTube Embed Code
<iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>How to Get the VIDEO_ID
Go to the YouTube video.
The URL looks like
https://www.youtube.com/watch?v=VIDEO_IDCopy the
VIDEO_IDpart afterv=
Example:
For URL:https://www.youtube.com/watch?v=dQw4w9WgXcQ
The embed code:
<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>Responsive YouTube Video Embed (using CSS)
<style>.video-container { position: relative; padding-bottom: 56.25%; /* 16:9 aspect ratio */ padding-top: 30px; height: 0; overflow: hidden;}.video-container iframe, .video-container object, .video-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%;}</style><div class="video-container"> <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen title="YouTube video"></iframe></div>Additional Notes
You can add
autoplay=1in URL parameters to autoplay (not recommended for user experience).Add
rel=0to hide related videos after the video ends.Use privacy-enhanced mode: change URL from
youtube.comtoyoutube-nocookie.com.
If you want, I can generate an HTML file with a ready-to-use embedded YouTube video for you!