Embedding YouTube Video as Valid XHTML 1.0
by Nazly on Tuesday, 11th March 2008 07:46:22
I always wanted to embed YouTube videos to my blog posts. But when I add the YouTube code to embed videos in my blog posts, I get validation errors from the W3C Markup Validation Service. I have been very careful on maintaining my blog to be XHTML 1.0 compliant. So finally I have found the solution to sort out the issue. The main reason being YouTube's use of the <embed> tag, which has been deprecated in XHTML 1.0. So I had to modify that code a bit to suit my need to be XHTML 1.0 compliant.
This is the code that YouTube gives to embed a video to a page
<object width="425" height="355"> <param name="movie" value="http://www.youtube.com/v/rybb85zc5yY"></param> <param name="wmode" value="transparent"></param> <embed src="http://www.youtube.com/v/rybb85zc5yY" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"> </embed> </object>
I changed it to
<object type="application/x-shockwave-flash" style="width:425px; height:355px;" data="http://www.youtube.com/v/rybb85zc5yY"> <param name="movie" value="http://www.youtube.com/v/rybb85zc5yY" /> <param name="wmode" value="transparent" /> </object>
I tested the code on all popular browsers and it works fine. If you come across any browser versions that has any problem with this code not displaying the video please do let me know with the browser and its version.
- 2 comments
- Filed under: HTML/XHTML, Technology
- Tagged as: embed, xhtml, youtube


























2 comments
Thanks for the tip on making YouTube code valid XHTML 1.0. I've always had trouble getting my drop down navigation menu to position above YouTube videos, and I didn't know about the "wmode" value="transparent", so I tried it and no my drop down menu works perfectly. Thanks!!!
by Scott on December 2, 2008 at 03:57. #
You saved me a whole world of grief!
by Matt on July 13, 2009 at 09:54. #