Return to Candy by James homepage

Why I use HTML (instead of xHTML)

Sean of Elementary Group Standards asked me, as part of a CSS Spring Reboot 2006 ques­tion­naire, why I used HTML 4. Was using HTML instead of xHTML a con­cious choice on my part? Absolutely.

While the other people who were ques­tioned man­aged to keep it nice and con­cise, I man­aged to write up a whole bucket load of words about it. As oth­ers asked me why I made sure Bite Size Standards is HTML 4, I’ve decided to post my answer here too.

As pub­lished on Elementary Group Standards:

“I’ve used xHTML for 5 years, from 2001 til 2006. My ori­ginal reason for using it was that it is sup­posed to be the future. It would have bene­fits like in-line SVG and MathML. It was presen­ted as TheThingToUse™ with CSS.

There are two things about xHTML which make it a poor choice for (pub­lic) sites. Both of them have to do with xHTML’s mime-types. In short, xHTML can be sent with text/html or application/xhtml+xml as the mime-type. On the web xHTML is usu­ally sent as text/html, as Internet Explorer (which has 83+% mar­ket share) doesn’t sup­port the other mime-type. Both mime-types are valid for xHTML 1.0, but (sup­port­ing) browsers do handle them differently.

It’s the hand­ling of the same code dif­fer­ently where xHTML’s prob­lem lies. When xHTML 1.0 is sent as text/html, it is handled as HTML. This means that it has zero user bene­fits over HTML 4.01.

When sent as application/xhtml+xml, you could use MathML — but — the browsers will also apply dra­conian error hand­ling. This way users vis­it­ing the site will be pun­ished (by not being able to see the site) for mis­takes by the cre­ator (which could be the developer, the CMS, the per­son updat­ing the text or indeed the user her/himself just writ­ing some­thing). Simple things like a mis­placed “&” on a page (instead of “&”) will com­pletely shut off a page from its users.

So not only are there no bene­fits over HTML 4.01 because you have to send Internet Explorer text/html — you do get user-punishing error hand­ling from other browsers if you decide to send to them the application/xhtml+xml mimetype.

No bene­fits but increased head­aches? Mwa, count me out.

Some people might say ‘but xHTML is the future!’ This may well be, but is of little con­sequence. The future ver­sions of xHTML (1.1 and 2.0) are not back­wards com­pat­ible with xHTML 1.0, so writ­ing xHTML now gains you little in the future. Furthermore HTML 5 is com­ing. Who says that can’t be the future?

My recom­mend­a­tions for writ­ing HTML? Use the doc­type ‘HTML 4.01 Strict’ and write your code as xHTML com­pat­ible as pos­sible. This means self-closing tags in the body, but not in the head.*

*Little known fact: It’s actu­ally in the spec that you’re not allowed to self-close the meta or link tags. Quite silly in prac­tical terms, and I would sug­gest to the HTML 5 people that they change that1.

I hope this answers all the ques­tions people have, but if you have any more (or dare to ques­tion my argu­ments!) don’t hes­it­ate to use the com­ment form accom­pa­ny­ing this journal entry.

Have a look at more Code or Hypertext

8 Responses to “Why I use HTML (instead of xHTML)”

  1. Funny, i use xhtml1.1 because of the dra­conian error hand­ling. I love the do or die approach. It pretty much guar­an­tees good code :)

  2. I know you do; And if it’s you — who knows xhtml by hart — using it, it can guar­an­tee good code. However, just one lil’ typo and you’ll be pun­nish­ing users for it.

    And for the web in gen­eral, it’s much bet­ter to have a “do or kinda do too” approach, wouldn’t you say?

  3. Ben Hunt says:

    I remem­ber read­ing in the SitePoint “DHTML Utopia” book that xHTML has some nasty weak­nesses when deal­ing with DHTML too.. Can’t remem­ber the spe­cif­ics though.

    Sometimes we just need to be reminded that, although xHTML may be newer and shi­nier, HTML4 is still *valid*, right?

  4. Ben Hunt says:

    Whoah, how DAMN cool is that!?!

    I put in my web site, and you look to see if I have a favicon set up, and use that as my glyph! Gold star to the boy at the back!!

  5. It’s not so much a “DHTML weak­ness” as much as xHTML can have a dif­fer­ent DOM. So two pages which might look the same, might have ele­ments you need to ref­er­ence dif­fer­ently in your JavaScript.

    Not only is HTML 4 valid, in most of the cases it’s JustAsShiny.

    And about the ‘glyph’: That’s just a favicon plu­gin for word­press — so while I can’t take too much credit for it, I’m glad you like it!

  6. BadHystrix says:

    Tah muchly!

    This is a most con­cise explan­a­tion of why NOT to use XHTML.

    Great for wav­ing at non-techy cli­ents and man­age­ment. :o)

  7. Umm… from the manual for the link element:

    Start tag: required, End tag: forbidden

    and meta:

    Start tag: required, End tag: forbidden

    So, what’s with the little known fact? Or did someone else give you false information?

Possibly related content

  1. No business benefits for microformats
  2. CSS3 Fonts: The ideal implementation
  3. On Horizontal CSS Centering using Absolute Positioning or how Relative Positioning can rock your css.
  4. About My Portfolio
  5. On the slagging of buzzwords

James John Malcolm MMXIII