Google and Amazon Generates Invalid HTML

By Xah Lee. Date:

Amazon Site Invalid HTML

More HTML validation Pain.

Here is a amazon ad widget from Amazon Associate site:

<iframe
src="http://rcm.amazon.com/e/cm?t=xyzxyz-20&o=1&p=11&l=ur1&category=textbooks&banner=17P1AE8RQ1T7ZFC62V82&f=ifr"
width="120"
height="600"
scrolling="no"
border="0"
marginwidth="0"
style="border:none;"
frameborder="0">
</iframe>

Of course it is not valid HTML. The ampersand needs to be &amp;. Also, there is no border="0" attribute for “iframe” tag.

Google Site Invalid HTML

Well, Google isn't doing much better. Here's the code given by youtube for embedding a video:

<iframe
title="YouTube video player"
class="youtube-player"
type="text/html"
width="640"
height="390"
src="http://www.youtube.com/embed/nnsSUqgkDwU"
frameborder="0"
allowFullScreen>
</iframe>

“iframe” tag doesn't have the “type” attribute type="text/html", and there is no such thing as “allowFullScreen”.

How bad can it be? So, from these 2 sites alone, handling out bad code, are directly responsible for millions of site being invalid HTML. Of course, all other video sites all hand out invalid HTML. None gives correct HTML as far as i know. 〔see How to Embed Video with Valid HTML

In the Google case, am sure they are just trying to solve a practical problem, though, i'm not sure it is absolutely necessary to resort to using invalid attributes. Clearly, the “allowFullScreen” is there to be parsed by JavaScript. If so, then it could easily be a comment tag instead, e.g. <iframe ><!-- allowFullScreen --></iframe>. And am not too sure that type="text/html" there is really necessary.

Google fixed it

I posted the Google's invalid type="text/html" problem to http://stackoverflow.com/questions/4800227/why-did-youtube-put-a-type-attribute-in-iframe-for-embedded-video , and also posted the question to TubeYou forum at http://www.google.com/support/forum/p/youtube/thread?tid=2fe9c0cb02f1558f

Amazingly, Google fixed it! Now the embed code no longer contains type="text/html". Yay!