There are only 10 legal XHTML empty tags
I’ve always had this nagging question. Is <a name="target"/> legal XHTML? I mean, it seems like kind of waste to have to do <a name="target"></a> all the time. Same thing with <script src="file.js"></script>, but I wasn’t sure if I could just arbitrarily use the empty element shorthand.
Turns out I can’t. There’s limited list of tags in the XHTML 1.0 DTD that can use the empty element shorthand:
A quick search for “empty” on the XHTML 1.0 DTD returns the following list of tags that can legally use the empty element shorthand:
<area/><base/><br/><col/><hr/><img/><input/><link/><meta/><param/>
Note: <a/> and <script/> are not on that list.
This post first appeared on From the Belly of the Beasts, a weblog from some of the people who build O’Reilly websites.
Can’t you use an ID attribute as an anchor? So rather than
<a name="foo"></a>you can do<a href="..." id="foo">. I hate that SCRIPT can’t be empty, it looks so stupid to have a closing tag when you’re including external javascript files.