Tag Soup: why using XHTML does not make sense.
Using XHTML instead of HTML to build web pages is one of today’s web design fads. Like other silly practices promoted by the web standards zealots (using CSS hacks for example,) this is something that will create extra work for no real PRACTICAL advantage and may even create problems for you!
People have been sold on XHTML with the typical web standards arguments that have a tendency to ignore the ‘reality in the field’. In this article I explain why you should stick to using good old HTML for the time being.
First, what is the reality today?
- Internet Explorer 6 and 7 (among other browsers,) will NOT render XHTML.
- If you use XHTML, DOM scripting and AJAX will be much more trouble.
- The supposed advantage (if ever realized,) are really minor at best.
Let’s consider these points:
BROWSERS AND XHTML
- When you serve XHTML to most browsers, your crazy-cool XHTML will be treated like ordinary HTML, thus loosing all the supposed advantages of XHTML.
- If you want browsers to treat XHTML as XHTML, you need to set the MIME type to: application/xhtm+xml. The problem is that IE6, IE7 and other browsers, will give you the ‘download this document’ pop-up box instead of displaying the page in the browser window.
- If you’re really intent on using XHTML, you could use scripting to sniff out browsers and change the MIME type accordingly, but this would lead to script-branching – if you wanted to use any DOM / AJAX scripts … more headaches.
HOW DOM SCRIPTING IS MADE HARDER WITH XHTML
The issue that stands out the most for me (and is enough for me to not use XHTML,) is that you can’t use ‘document.createElement’ to create new elements with the DOM if you are using XHTML.
In case you don’t know, ‘document.createElement’ is one of the key methods of DOM programming and by extension AJAX.
-
This topic was recenty discused on the message board:
Stefan Mischook
December 6th, 2005 at 5:22 am
Hi There!
I take some of your points, but I converted around 90 % of my web pages to XHTML Trans this September and all of those pages do load really easily on IE6 although your article says that this does not happen. Maybe I would have a problem if they were XHTML Pure, although – there again – I pesonally use IE6 and have no probs with web pages written in XHTML Pure.
Robin.
December 6th, 2005 at 8:22 am
IE is the only major browser that will puke using application/xhtml+xml, but being 70% – 80% (dependig on the source) of the market, that is a big problem.
The second biggest problem is that by sending it as application/xhtml+xml, you are correctly serving it as XML, this means if your page has even one error, the parsing will stop and the user will see nothing more than a white page with a error. So your page has to be perfect.
The rest ofthe quirks are discussed in the mentioned thread. But as quick links may I suggest you call up the following test page in Firefox/Mozilla/Opera, and then open it up in IE to see what we mean. (http://juicystudio.com/mimetest/xhtmldoc.php)
Ths is one (the second) of the tests created by Gez Lemon to show the problems with XHTML being served correctly or as “Tag Soup” (XHTML written, but served to the browser as HTML by using text/html, the default setting). (http://juicystudio.com/mimetest/index.php)
I personally know many “Standards Zealots” who do not support the use of XHTML as tag soup suggesting that HTML is fine for 99% of all web sites. Gez Lemon, Redux and Tommy Olsson to name a few.
Stef is right, ifyou are still going to use it (as I do on my personal sites, not customer sites anymore), then read up on it and understand the matters at hand first and make a informed decision.
Good article Stef, short, but good **grin**
December 6th, 2005 at 10:10 am
@Kyle,
As always , great comments.
Thanks
December 6th, 2005 at 12:35 pm
Hi Robin,
you are missing the point. If you read up on XHTML at the W3C you will see that XHTML is meant to be served as XML (application/xhtml+xml). XHTML is XML and not HTML.
You may be writing XHTML, but it is being served as HTML, this is called Tag soup. If you check the page info with Firefox or Mozilla you will see it shows text/html.
MimeTypes are sent when the page is requested, so you must tell the server you wish to have application/xhtml+xml. So you must use Content negotiation for this.
IE can read tag soup, with XHTML 1.0 you may serve XHTML with text/htmlas long as it meets Appendix C. But XHTML 1.1 and the upcoming 2.0 MUST be served as application/xhtml+xml. That is when IE will puke. As long as you write XHTML but gove the browser HTML to show, yes it will work in IE as well. You should try the test suite I linked above and read some of the links I posted on the forum, it will clear things up better than we can here in comments. If you are a member fo the forum just ask on the linked thread above and I can get into more detail.
LSW