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:

Comments

11 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!

  6. Dan Leitch on September 27th, 2010 2:37 am

    Thanks for sharing that, to be pedantic the embed tag is not deprecated, it never officially existed in the first place, as far as I know it never passed any form of validation.

  7. David Beesley on October 11th, 2010 2:44 pm

    Many Thanks, this code was awesome for one of the web projects I am working on.

    Dave

  8. Tiff on April 25th, 2011 5:55 pm

    Thank you so much! I am very happy when I type in Google search, “youtube html xhtml 1.0 strict code” returned this as the #1 result. Keep up the good work, dude.

  9. derylius on September 16th, 2011 8:00 am

    sadly youtube no more support this type of code, since they use iframe wich looks much better in code but not valid in xhtml 1.0 strict

  10. kaka on October 23rd, 2011 8:33 pm

    Thank you for sharing the code. It helped me a lot.

  11. Naveen P Suthar on March 9th, 2012 11:05 am

    Its good……. but sadly it dose not support Internet Explorer 9 not even in compatibility view.

Leave a Reply