Embed YouTube videos with XHTML 1.0 Strict code

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:

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:

12 Replies to “Embed YouTube videos with XHTML 1.0 Strict code”

  1. …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…

  2. 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.

  3. 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.

  4. 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

Comments are closed.