<div class="clear"/>
When serving an XHTML page as text/html
, browsers do not read it using a real XML parser. Instead, they use a basic HTML parser that does not recognize self-closing tags. To an HTML4 parser, a self-closing tag appears as simply an open tag with strange punctuation in it. Until IE9 becomes more widely used, we cannot serve general web pages as application/xhtml+xml
, which is necessary for browsers to utilize real XML parsing rules. This means that if you are writing XHTML documents, you must also make them compatible with plain HTML by always and only using self-closing syntax on elements like img
and br
.
There are additional rules for writing HTML-compatible XHTML outlined in Appendix C of the XHTML 1.0 standard. While this may seem overwhelming, many of the points address outdated features or irrelevant topics related to old browsers. For example, the practice of including a space before />
is no longer required by any commonly used systems.