Use less DIV, use more HTML - Part Deux

👉 Whoa! Please note that this post is 15 years old. The views expressed within might have become outdated.

Arjan Eising posted an interesting comment to my previous article:

Nice job done on this... but what will happen when you don't use the body element for instance? While it is not needed to markup your text valid...

This article provides an answer.


As I expected, the techniques presented in "Use less DIV, use more HTML" work fine in documents where the BODY or HTML elements are omitted.

I'm not entirely sure how this works, but as I understand it; modern browsers add these elements when rendering your document. Don't take my word for it, I'm not at all sure about the technical details behind this.

Word of warning: when omitting BODY or HTML in XHTML, these examples won't work. Anne van Kesteren says here:

When you are really using XHTML, which is different from most XHTML you just have to make sure you got the namespace right and the rest is up to you. Note that when you are leaving out an element in (real) XHTML (I dislike to put the term "real" in front of it) it really isn't there, this is different from HTML when you can try to leave out an element by omitting it's start and end tags, but it will be there.

Last but not least, the actual example can be found here. I created another example here that uses a more complicated CSS selector, that, to me, proves there are indeed a HTML, HEAD and BODY element available in the document.