YouTube is great for sharing videos. However, when you want to embed those videos on your own website, it can be difficult to validate the ’embed code’ that they give you, especially when you are using the ‘XHTML 1.0 Strict’ doctype.
Google now gives you the option of ‘iframes’ or the old ’embed’ code. Despite the iframe option being made available for the HTML5 specification, you’ll still find they don’t validate in ‘XHTML 1.0 Strict’! How frustrating.
Well, there is a way of changing the old ’embed’ code to make it compliant. Here is the code to make your YouTube videos validate correctly:
<object type="application/x-shockwave-flash" style="width:560px; height:340px;" data="http://www.youtube.com/v/Tlmho7SY-ic">
<param name="movie" value="http://www.youtube.com/v/Tlmho7SY-ic" />
Just remember to change the width, height and URL in this example to match your own YouTube video – you can find the URL and appropriate relations to the video via the embed section on YouTube. Or if it’s easier, just copy the unique URL code (in this example replace ‘Tlmho7SY-ic’) from the YouTube address bar and you’re done! You will have to repeat the URL in the ‘data’ and ‘value’ sections for this code to work correctly. Hopefully this will save you a few headaches.