"Should I learn HTML or XHTML?"

Tags: 

I've actually been asked this question several times lately, where someone wants to either brush up on their little used and mostly forgotten skills, or is looking to learn from scratch. The answer to the question is simple: XHTML all the way, and here are my reasons:

  • With XHTML you have to close every tag, rather than e.g. leaving paragraph tags hanging around on their own. This will lead to much more organized and clean code as all tags will be correctly nested.
  • Cleaner code will lead to fewer bugs as it will be easier to keep track of the code.
  • Having all attribute values in quotes means you longer have to wonder why your <img src=/images/oh so important.png> image doesn't work right.
  • The syntax rules force others providing content for the site also have to keep their work in check, which can avoid conflicts.
  • XHTML means no font tags, so you have to do your design in CSS. This starts pushing sites towards separating the content from the presentation, which is a very good thing.
  • XHTML doesn't allow the BLINK or MARQUEE tags, which should be the number one reason to use XHTML - they're evil and as developers it is our job, neigh our duty, to save managers from themselves.

3 Comments

Hey Eric, thanks for stopping

Hey Eric, thanks for stopping by. IKWYM. I became extremely picky about closing my tags after discovering how my unclosed table cells looked in Netscape 3 ;-) CSS positioning took me a while to get but I can now fly along with it, if I've got a design to follow.

What's funny is that when I

What's funny is that when I learned HTML (in '94/'95) I followed all of these rules. So it was surprising to me that when I went to learn XHTML all I had to start doing was self terminating tags like br, img, and input, and drop the deprecated tags from my library (font). I was already avoiding blink and marquee, since they were IE only.

A good way to enforce web

A good way to enforce web standards this is to get the appropriate doctype before your markup. That way a quick validation will show you how much you have deviated away from W3C compliance.