Why use XHTML

One question that pops up over and over on various forums are arguments over whether HTML or XHTML is the better choice for dfinng web pages. Most of the arguments put forward for using one or the other are not really all that compelling. Certainly they are insufficient to sway those who support the opposite case.

The best argument in favour of HTML would be that Internet Explorer 6 (the latest version of IE at the time of writing - even though it is over 6 years old) does not support pages served as XHTML an so it becomes necessary to tell the browser to treat the XHTML as if it were HTML. The standards only allow XHTML 1.0 Transitional to be so served and so you are limited to that version of XHTML. As the browser is going to process the page as if it were written in HTML 4.01 anyway the argument is that it should be so written in HTML in the first place.

A seconary argument that is rarely put forward in these discussions is that Javascript needs to be coded somewhat differently for use with XHTML than it does for HTML since XHTML uses multiple namespaces. This makes it just about impossible to write Javascript that will run on both HTML served pages and XHTML served pages. Of course if the XHTML pages are served as HTML then this problem disappears but then so do most of the arguments for using XHTML instead of HTML.

Probably the most common arguments put forward in favour of XHTML are that the standards define XHTML 1.0 as the XML based equivalent to HTML 4.01 and that the next version (currently under development) will be XHTML 2.0 and not HTML 5.0. This indicates that XHTML is expected to completely replace HTML at some point in the future (when remains to be seen). Other arguments for XHTML are that it is more consistent (since all tags must be closed) and that people who choose to code in XHTML are more likely to validate their page and hence produce more functional web pages than those who are using HTML simply because that is what their chosen editor creates for them.

None of these arguments (or any of the others I have seen) are sufficiently compelling to overthrow the arguments put forward for the reverse case and so in these instances it basically ends up coming down to personal preference as to which you personally believe is the stronger argued side and which you therefore decide to use for your code.

There is however one situation that I have not seen mentioned in any of the forum discussions where XHTML is the only possible alternative and you can't use HTML. XML (eXtensible Markup Language) is rapidly being adopted as the gemeral markup language of choice for defining data. The next version of Microsoft Office (for example) will use XML in place of the proprietary formats that prior versions use for storing your documents, spreadsheets etc. One big advantage that XML has over proprietary formats is that it can be easily transformed into a variety of other document types simply by defining an appropriate XSLT transformation file. This allows the same source to be transformed into many different display formats for use for different purposes instead of having to convert between formats and keep multiple copies of the actual data content in those different formats. Since XHTML is an XML derivitive the XSLT statements required to transform your XML document into an XHTML web page are relatively simple to code. Since it is not possible to transform XML into HTML without ending up with the additional closing tags that XHTML requires that HTML does not there is no point in trying to call the resultant generated page HTML since it is the XHTML equivalent regardless of what you call it and therefore will only validate as XHTML.

As XML gradually gains in importance for storing original source data the idea of generating web pages directly from that XML will gradually gain in popularity and with it will grow the XHTML user base. While there is little to choose between HTML and XHTML now, the future obviously is with XML and XHTML. You just need to make the decision when you wish to start preparing your web pages for that future.

When will I make the decision to move to XHTML? Well I made the move before I started writing the pages for this site back in September 2000.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate