Sunday, February 20, 2005

HTML or XHTML?

SitePoint Tech Times: "XHTML 1.0 is a language for writing Web pages using the same tags as HTML, but with the more tightly controlled tag syntax of XML. XHTML makes it easier for programs of all kinds to read and generate Web pages, while making the job of the Web developer only slightly harder.

XHTML also allows for other XML-based tag languages to be mixed into a Web page for specialized needs (e.g. MathML). Browsers that support these tag languages can then display such specialized content within the page. This extensibility puts the 'X' in XHTML.

The case for avoiding XHTML was pointed out to me by the author of SitePoint's upcoming DHTML book, as I tut-tutted his use of HTML (as opposed to XHTML) for the book's sample code.

Here it is in a nutshell:

1. Browsers decide how to handle a file based on the MIME type that the server sends with it.
2. HTML Web pages are identified with a MIME type of text/html.
3. Pages written in XHTML that are sent with a MIME type of text/html don't benefit from any of the features of XHTML.
4. To benefit from the features of XHTML, pages must be sent as application/xhtml xml.
5. The most popular Web browser (Internet Explorer 6) cannot view pages sent as application/xhtml xml.

From this, it follows that you cannot benefit from using XHTML without breaking compatibility with Internet Explorer 6. So you might as well just use HTML.

With this in mind, the case for using XHTML is a lot weaker than I had come to believe. What it comes down to is 'Web standards are good, so to help promote them, support XHTML by implementing it however you can. Your clients all want it anyway.'

What most standards-conscious professional developers do today is write XHTML and allow browsers to treat it as HTML. Meanwhile, advanced developers who want to take advantage of XHTML can configure their servers to send XHTML pages as application/xhtml xml to browsers that support it (not Internet Explorer).

Assuming that isn't practical for you, you're left with a choice: support the XHTML standard by feeding it to browsers that expect HTML, or stick with HTML and send browsers what they expect to receive."

-- Yikes! I didn't know this about XHTML. Me, up on my standards soapbox all the time... Well, good thing I use Mozilla Firefox! With IE7 supposedly coming out this summer, who knows - this ignorance on IE6's part may be solved, and this issue will be no more. But, I will continue to code my sites in XHTML to support the continued progression of web standards, while my web servers keep sending out the XHTML code as HTML type. My reasons for using XHTML have more to do with supporting the standards than with displaying my sites on other devices like cell phones and the like. The appolication MIME type issue, then, really doesn't affect me.

No comments: