Empty HTML Elements In XML

Suppose you want to write some text which is at the same time both HTML and XML. Well, this isn't too hard; all you have to do is put in all the tags you usually leave out (like for example <BODY>), quote your attribute values (no more <P align=right>), and you should be OK.

There are some problems, specifically HTML's empty elements such as IMG, HR, and BR. Of these, you can crack the IMG and HR nuts simply by putting in end-tags, for example <IMG SRC='madonna.jpg'></IMG>; which looks a little weird, and will not be valid for some SGML parsers, but won't cause a browser any heartburn.

BR is a real problem, though. Sure, you can double it up like so: <BR></BR>, but most browsers, when they see this, will stupidly put in two blank lines, which really uglifies your page. However, it turns out that if you use <BR /> (there's a space between the BR and the /) then everything works just fine. The guys at Netscape once explained to me why this works, but thank goodness I had signed a non-disclosure agreement, because it's not a pretty story.

Back-link to spec

Copyright © 1998, Tim Bray. All rights reserved.