Embed YouTube videos with XHTML 1.0 Strict code

April 14, 2009 · Posted in Misc 

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:

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Slashdot
  • Technorati
  • TwitThis

Comments

2 Responses to “Embed YouTube videos with XHTML 1.0 Strict code”

  1. Ben on July 24th, 2009 3:49 pm

    Thanks for posting this code. It works perfectly, and was exactly what I was looking for.

  2. Steven on November 25th, 2009 6:13 pm

    THANK U EXCELLENT

Leave a Reply




  • Gary Pendergast, noun: Gamer, developer, MySQL, WordPress, web and music geek. Currently taking a leave of absence from life as a MySQL Support Engineer for Sun Microsystems to tour around Europe. Can be observed in his natural habit at pento.net, or usually in Bologna, Italy.

  • My Twitter