On the various meanings of <tag />
With the growth of XHTML, some HTML documents have started sprouting
things of the form '<tag />' or '<tag/>', intended to represent
empty tags. Sometimes this is due to attempts at XHTML to HTML
compatibility, and
sometimes it's just due to HTML superstitions. (Most people who write
HTML are not experts and have not read the W3C specifications, so superstitions are
not uncommon.)
These people and documents are making a mistake. Unfortunately, there
are three entirely separate things that <tag /> can mean:
if you are actually successfully serving XHTML,
this is an empty (self-closed) element. (Hopefully it is an element
that can actually be empty.)
in HTML in all the major web browsers, this means 'tag, with an
attribute called "/"'.
in strictly compliant HTML, including as parsed by the W3C
validator, this means '<tag>>',
because it is actually a SGML feature called minimization.
The difference between validators and browsers is an especially
pernicious gotcha; a web page can pass validation, but in a completely
different way than how a browser will interpret it. (It happens because
validators usually use a real SGML parser, completely with all of the
obscure features, but browsers do not.)
It is very fortunate that no popular browser actually implements tag
minimization, because no one expects them to. Also, HTML has some
remarkably dark corners where you can get eaten by a grue.
If you want to read more about this, Empty elements in SGML, HTML, and
XHTML will give you all
of the detail and background that you could want. (There you will also
find a nice example of why you should always put attribute values in
quotes.)
(I owe my exposure to these pages and this issue to plasmaturm.org and Frank Hecker.
And in truth in advertising, the final impetus for
writing this down was provided by this blog entry.)