How to embed YouTube video in HTML

Embedding a video from YouTube is quite simple. In this post, I’ll show you how to embed YouTube video in HTML.

Time needed: 2 minutes.

  1. Go to YouTube and select the video you want to embed.

  2. From the options in the bottom of the video, select SHARE.

  3. Select Embed from the box that appears.

  4. From the next popup, select appropriate options and copy the HTML code.

  5. Paste the code in your HTML code.

Example

This is the code i have copied. Place it in your HTML page.

<iframe width="560" height="315" src="https://www.youtube.com/embed/8S_nSP76YGE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Alternate methods

You can also embed youtube video in HTML using <object> and <embed> tag as shown below.

Note: Using <object> and<embed> is deprecated.

<object width="420" height="315" data=" 
https://www.youtube.com/embed/8S_nSP76YGE">
</object>
<embed width="420" height="315" data=" 
https://www.youtube.com/embed/8S_nSP76YGE">
</embed>

If you enjoyed this post, let me know by leaving a comment below.


Leave a Reply

Your email address will not be published.Required fields are marked *