In your question title, you ask about HTML, SGML and XML as if they are the same thing, but they are not. In fact, they are very different in precisely that area which you are asking about.
In particular, SGML has both Null End Tags and Implied End Tags (and Implied Elements as well), and since HTML is an application of SGML, it inherits those.
Null End Tags allow you to leave out the name of the End Tag. Instead of
You can also write
Implied End Tags allow you to leave out the End Tag altogether, if it is clear from the context that there must be an End Tag. For example, in HTML, a
body element cannot be inside a
head element, therefore you can write
and both the
head elements will be implicitly closed.
End Tags are also implied at the end of the document: all elements will be closed in reverse order.
With Implied Elements, you can leave out both Start and End Tags: since
p is only allowed within
body, the first
p will imply a
Here, there is a
body element in the document, even though there are no
Putting it all together, you get something like this:
<TITLE / > /
<P / >
This is a complete, 100% well-formed, 100% valid HTML document. (Well, it's missing the
DOCTYPE declaration, but if you add one, you can run it through the W3C validator as HTML 1.0, 2.0, 3.2 and 4.01, even as Strict.)
It is semantically equivalent to the following XHTML:
Now, which one of the two is easier to read?
(Actually, that's a serious question. I'm particularly interested in what seasoned Lisp programmers have to say.)