HTML documents without html, head and body elements
Just a few hours ago the results of the second CSS OFF competition became public. Dan Ott won this time, and as also said in the comments over there: congrats Dan! More important than winning are the results from everybody who competed. A lots of useful ideas for Front-End techniques can be found over there. A comment on my entry was made about the non-usage of the html, head and body elements.
So what’s that about? To know what I’m talking about, take a look at my entry. As you see: no html, head and body elements. If you want, you can also try to validate the document. As you may see, it passes the validation. As far as I know, the html, head and body elements shouldn’t be used, but could be used.
Now take a closer look at my document. In the stylesheet, you might see at the top of the document the body used as selector. The body element isn’t a box like a div, it is the viewport (not exactly, but it comes closer than a div). As we all know, you can set the background to the body, and even without any text it has that color for the hundred percent of the height of the browser window. And as there always is some kind of viewport, there is also always a body element in all HTML documents. I came across this at Harmen Janssens web log in this article.
Like CSS, the same thing goes for JavaScript. If you try to access the body element via document.getElementsByTagName('body')[0], it will return your ‘invisible’ body element reference.
Everything works nice, and is different from the expectation you might have. There is only one exception on this non-usage of these elements. When you markup your document as XHTML, send it with mimetype application/xhtml+xml and use the correct namespace, this all will not work. Mainly because your page is handled as and XML document, and therefor it uses the XML DOM instead of the HTML DOM.
So, now you have a lot of new information. But what do you think of the non-usage of these elements? I’d like to hear some additions and critique on this point, also because I’m not an expert on this part of serving documents.
Posted on Thursday, August 9th, 2007 in HTML
Comments and trackbacks are welcome.
