How to embed video from youtube in valid xhtml transitional using tag ‘object’


Hi there,

I had a problem embedding video from youtube in my blog. Myblog was perfectly valid in xhtml transitional, but once i embedded the video it didn’t validate anymore.

This was the original code from youtube:

<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ width=”425″ height=”344″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/
flash/swflash.cab#version=6,0,40,0″><param name=”allowFullScreen” value=”true” /><param name=”src” value=”http://www.youtube.com/v/Z-DVi0ugelc&hl=en&fs=1″ />
<embed type=”application/x-shockwave-flash” width=”425″ height=”344″ src=”http://www.youtube.com/v/Z-DVi0ugelc&hl=en&fs=1″ allowfullscreen=”true”></embed>
</object>

The code above doesn’t validate in xhtml transitional.

In order to validate in xhtml transitional, all what you need to do is modify the code above so that you get the code below:

<object type=”application/x-shockwave-flash” width=”425″ height=”344″ data=”http://www.youtube.com/v/Z-DVi0ugelc&hl=en&fs=1″>
<param name=”allowFullScreen” value=”true” />
<param name=”src” value=”http://www.youtube.com/v/Z-DVi0ugelc&hl=en&fs=1″ />
</object>

  1. remove classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ and codebase=”http://download.macromedia.com/pub/shockwave/cabs/
    flash/swflash.cab#version=6,0,40,0″
    from the tag <object>
  2. include within the tag <object> the attributes type=”application/x-shockwave-flash” and data=”http://www.youtube.com/v/Z-DVi0ugelc&hl=en&fs=1″ where the link in data is exactly the same link as the one that appears in src within the tag <embed>. (in this case src=”http://www.youtube.com/v/Z-DVi0ugelc&hl=en&fs=1″)
  3. now delete the tag <embed> and all the code included within it.

Done! ;)

Now your code validates in xhtml transitional!

2 comments

  1. Patrick says:

    But which do you prefer – markup that works, or markup that validates?

    You can have the best of both worlds with JavaScript that inserts DOM object/embed elements according to the capabilities of the browser.

    See the SWFObject project on Google Code.

  2. Karen Hayes says:

    Youtube is my favortie site to visit aside from facebook. most of the time i watched movie trailers and music videos on it.

Leave a Reply

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

*