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
  • Twitter
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • Slashdot
  • Technorati
  • StumbleUpon

Comments

5 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

  3. fantasmo on May 5th, 2010 2:21 pm

    …but it doesn’t work on the iPhone.
    Does anybody know how to embed Youtube for iPhone and still be xhtml strict valid? …and stil stay on the website (no forwarding to the youtube website).

    I’m desperately searching for a solution…

  4. danilo on June 17th, 2010 4:19 pm

    thanks a lot for sharing this!

  5. danilo on June 17th, 2010 4:20 pm

    thanks for sharing!

Leave a Reply




  • 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