Thursday, September 25th, 2008

Make your YouTube embed code validate as xHTML 1.0 Strict

After rebooting the University of Baguio Science High School up to version 3.5, I ran into some xHTML validation errors with the MultiMedia page which features some TV Commercials of the school hosted on YouTube. It appears that the deceptively simple HTML code that YouTube provides fails to pass the W3C HTML Validator.

Here’s the embed code that YouTube supplied for the UBSHS Belong TV Commercial:

<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/LuV_Nd8iyQA">
</param>
<embed src="http://www.youtube.com/v/LuV_Nd8iyQA" type="application/x-shockwave-flash" width="425" height="350"> </embed>
</object>

Based on this code, the W3C Mark-up Validator put out several warnings that included errors on the “element ‘embed’ undefined”. Any page that includes YouTube’s generic embed code will thus fail validation. While this may come as no consequence to most people, since the video will generally work with most browsers, any self-respecting web developer would find the generic embed code rather cumbersome.

With the goal of making the embed code pass validation, some redundant and outdated code can be removed and we get the following:

<object type="application/x-shockwave-flash" width="425" height="350" data=" http://www.youtube.com/v/LuV_Nd8iyQA ">
<param name="movie" value=" http://www.youtube.com/v/LuV_Nd8iyQA” />
</object>

Now that’s better! We’ve effectively reduced the number of characters in the embed code from 227 down to 183 in a less cluttered 3 lines. This modified YouTube code passes validation as xHTML 1.0 Strict and the video plays just as well as the original!

Category: Geek, Internet
You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.