I thought XHTML documents were supposed to be displayed with exactly the same standards compliance mode as "strict" HTML documents.
However, there is a difference in how they display pre
elements: in HTML documents, if the <pre>
start tag is followed by a LF (or CRLF), this is ignored. Not so in XHTML.
Example: a HTML file and a XHTML file that have the same content, but are rendered differently.
(Or if you think it's cheating to give a HTML file and a XHTML file exactly the same content, including DOCTYPE, here are two files that follow more classic rules: HTML 4.01 strict and XHTML 1.0 strict.)
So, does that mean that statements like this W3C page's
all line breaks and spaces are rendered exactly as they appear in the HTML. The exception is a newline immediately after the start tag <pre> and immediately before the end tag </pre>, which are discarded.
are only valid for HTML, not for XHTML? I haven't found any indication that XHTML can display things differently if it likes. But all the browsers I've tested do.
The removal of the starting newline is nothing to do with the rendering in HTML, and Dave Raggett's page is just a little imprecise and getting a little out of date. The removal of the starting newline is a property of the HTML parser.
In the in body tree construction phase the HTML5 spec for the
text/html
mime type says:An XML parser is simply not allowed to do this by the XML parsing rules, so XHTML does not drop that new line.