if ( knowledge ) {

A place for thought, progress, and dissent.

Wednesday, January 19, 2005

Putting the X in HTML

I'm on a standards kick. Since I've been doing more web development lately, I decided to jump into XHTML and CSS full force. I had used CSS before, but XHTML 1.1 (and 1.0 Strict) requires that display tags be separate from the XHTML, and CSS (or XSLT, etc.) be used exclusively. (for the semi-tech-saavy: this means no <FONT> tag, bgcolor attribute, or anything like that)

So I'm now a standards junkie. I wrote the Project preVote site (and another one in progress) using XHTML 1.1, but today I went to the next level. Web guru Roger Johansson posted The Perils of Using XHTML Properly today, and points out a few difficulties of moving to proper XHTML. After some tewaks, preVote is now correctly serving (on my testing server; eventually at the real site) "application/xhtml+xml" to browsers that can handle it, and "text/html" to older browsers. This coupled with strict usage of XHTML and CSS means that I'm completely standards compliant!

Here's a real-world example of a peril. If you send a page as "application/xhtml+xml" to FireFox and it contains even one improper tag (this could be <br> instead of <br />, or class="mainArea" instead of class="mainarea"), it will display an error instead of the page!

So other than giving me a sense of accomplishment, what does this do? Well, it means consistent rendering in future browsers. It also means these sites will be able to use cool tools like XSL someday, if I wish. It also means that every part of the sites are valid XML and are therefore more flexible.

But proper (and strict) XHTML isn't easy. I was only able to do this because these sites are in their infant stages. If I were starting with a large site written in HTML 4.1, this task would be much more difficult with no imminent rationale to change. My goal is to keep these sites proper as they grow. It should make my life easier in the long run.

0 Comments:

Post a Comment

<< Home