Use less DIV, use more HTML - Part Deux
Posted on 29 March 2007 (04:08 PM)
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.
Filed under HTML and CSS
- ← previous article: Use less DIV, use more HTML
- → next article: Where do elements go?
Comments:
Nice follow up! I have heard from this before (that's actually why I asked) about this. So save bandwidth witht leaving the body and head elements out, I would almost say :p
Yeah, why not?
I don't see any harm in omitting those elements.
I would really like to know about any disadvantages of leaving them out..
What if future browsers stop putting in those elements in the generated source? You'd sure have a problem then. Besides, I don't think you have any control what goes in the head and what goes in the body, which can be relevant for JavaScript execution if I'm not mistaken.
You're right, browser support is something to keep an eye out for, although I think browsers will support it for a long time, preserving backwards compatibility.
About what goes in the head and what goes in the body: that's worth some testing, keep an eye out for a new article in a little while :)