How to embed YouTube video using object tag?

9.3k Views Asked by At

I am trying to include YouTube video by object tag in HTML:

<object width="500" height="500" data="https://www.youtube.com/watch?v=aqsL0QQaSP4"></object>

Currently, the video doesn't display. I searched on W3Schools, they have similar code with a different URL and it works:

<object width="420" height="315"
data="https://www.youtube.com/v/XGSy3_Czz8k">
</object> 

What kind of URL can I use for the object data attribute?

2

There are 2 best solutions below

2
On BEST ANSWER

Figured it out. You need to add a "v/" to the end of youtube.com. Basically, the new video link that you embed is https://www.youtube.com/v/watch?v=aqsL0QQaSP4

<object width="420" height="315"
data="https://www.youtube.com/v/watch?v=aqsL0QQaSP4">
</object>

0
On

YouTube's recommended way of embedding videos is using iframe. This is what it would look like:

<iframe width="854" height="480" src="https://www.youtube.com/embed/aqsL0QQaSP4" frameborder="0" allowfullscreen></iframe>

EDIT: If you wish to use the <object> tag, check out my other answer.