Embed YouTube videos with XHTML 1.0 Strict code

April 14, 2009 · Posted in Misc · 5 Comments 

Being a bit of a web geek, I like to keep my sites running in Strict mode for whatever HTML/XHTML version I happen to be working in. So, I was saddened to discover that the Embed code that YouTube gives doesn’t pass XHTML 1.0 Strict, due to their use of the now deprecated embed tag. Happily, there’s a way to fix this. As a bonus, the code required is much nicer than the code YouTube gives you:

<object type="application/x-shockwave-flash" style="width:480px; height:385px;" data="http://www.youtube.com/v/p1QMoQ3jbjc">
    <param name="movie" value="http://www.youtube.com/v/p1QMoQ3jbjc" />
</object>

You just need to replace the two URLs with the one for your video, and set the appropriate width/height. YouTube’s defaults are 320×265, 425×344, 480×385 and 640×505.

There you have it! It’s a simple as that. And to prove it works, here’s the same code from above:

  • Picture of Gary Gary Pendergast, noun: Gamer and developer. MySQL, WordPress, web and music geek. Currently employed as a MySQL Support Engineer for Oracle. Can be observed in his natural habit at pento.net, or usually in Melbourne, Australia.

  • My Twitter