Grow your CSS skills. Land your dream job.

XHTML 1.1 or HTML 4.01?

Published by Chris Coyier

NOTE: This article is super old. As I write this warning in mid-2013, there is only one DOCTYPE that should be used, the HTML5 <!DOCTYPE html>

Aaron Bazinet originally posted this question in the forums.

I'm going to go ahead and say right away I'm not an expert on this subject, but I do find it quite interesting. The first line of every page we design starts with a DOCTYPE, and I have a feeling that most of us don't have a real strong grasp on all that it means.

The code-peakers amongst you will probably notice right away that CSS-Tricks uses XHTML 1.0 Transitional. Yeah that's probably not good, for reasons we'll touch on. To be honest, when I first coded CSS-Tricks, I understood much less than I do now, and I'll likely be changing this soon.

I think the best place to start is in the year 2000 when XHTML 1.0 became the official recommendation of the W3C. It literally was designed as the successor to HTML. So here we are more than 8 years later. We are now at XHTML 1.1 (1.2 is still being worked on, and 2.0 is a long way off). And we are still talking about whether we should be using it at all.

In 2002, there was already talk about how XHTML leads to better living. Then in 2003, the first edition of Jeffrey Zeldman's Designing with Web Standards was released (now in it's 2nd edition, 2006). Many of us probably own and have read this book. To be honest it feels kinda outdated when you read it now because the example seem so basic and the designs seem so old school. But, it's still probably considered to be the closest thing to "The Bible" of web standards. This book is absolutely jam-packed with XHTML lovin'.

So those of us who are fans of Zeldman, A List Apart, Happy Cog and that whole crew, we drank the kool-aid and starting using XHTML. Is that good or bad? I just don't know.

Here are some points to consider:

  • XHTML is more like XML. That means your code has to be written a lot cleaner. No uppercase allowed (in tags). Every tag absolutely must be closed. Clean code is good right? I think so. But, not closing a tag can have a lore more dire results than in HTML, that's not good, right?

    Because XHTML is more like XML, it's a lot more extensible. Here is what the article XHTML - Myths and Reality has to say:

    ...This will make it possible for an author to express more structures and richer semantics than is possible with HTML today. In effect XHTML inherits the possibility of supporting more than one language instead of extending HTML in a monolithic fashion, XHTML can be extended through modules, where each module define a specific subset of the language.

    This, theoretically, means extension of the language can be done without the need for a browser upgrade.

    Hey that sounds pretty cool! But... how many of us will ever use that ability? 0.01%?

  • XHTML isn't always interpreted as XHTML. I don't fully understand this yet, but apparently a large numbers of browsers don't take advantage of the fancy things XHTML can do anyway. IE 8 will be the first version of Internet Explorer that supports it all. Doesn't mean that your site will be broken, just means that the code will be interpreted as regular HTML anyway. From what I understand, general consensus is that HTML 4.01 is the way to go for the most widespread support.
  • Minor considerations about CSS. Since this is, you know, technically a site about CSS it's worth mentioning there is a little thing to keep in mind about CSS and these different DOCTYPES. In HTML, some tags will automatically get applied to the document, like a <tbody> inside a <table>. So in CSS, you can declare something like "tbody td" and be confident that rule will take effect, even if you leave the tbody out of your code. Not the case in XHTML.

One thing that is for sure, is that there is no clear cut answer. If I had to make up my mind right this second I'd say that HTML 4.01 kinda makes more sense for most regular web designers / web sites. I should also say that I've designed a crapload of websites blindly just using XHTML 1.0 Transitional, they all work and I'm still breathing.

So don't yell at me too bad, but feel free to enlighten me and the rest of us if you know more.

Great reference in the SitePoint forums here.

Oh yeah, and isn't it funny we were discussing HTML 5 vs. XHML 2? Ha.

Comments

  1. Permalink to comment#

    I personally use XHTML strict in all websites that I design. I love its clean-code, no-nonsense behavior. HTML 4.01 looks fugly to me ever since I started using XHTML. 100% browser support for XHTML be damned – as long as it works, why fix it?

  2. Permalink to comment#

    Strange comment::

    What is IE 8 going to be closest to? XHTML 1.0 or say HTML 4.01 strict?? I have heard all sorts of comments on IE8 being “standards compliant”, but what does this really mean?

  3. Permalink to comment#

    I always use XHTML Strict since I realised its existence. BTW, it is the only doctype which switches IE6 to strict mode, so that you do not have to play around with its crappy box model implementation.

  4. Rob
    Permalink to comment#

    IE8 will be 10 years behind all other browsers in standards compliance and continue to be the worst browser on the planet.

    btw, no one should use XHTML 1.1 because it MUST be served as application/xml and no one here does that, I’m sure. Of course, that’s why no one should bother using XHTML either sine no here serves it and only modern browsers (not IE) understand it.

  5. trice22
    Permalink to comment#

    I’ve been lately thinking about where I’d like to go with things and I guess I’ll stick with XHTML (strict) as well. I can’t really get warm with HTML and never could. Actually: if I’d be king for day, I’d push things mark–up wise somewhere into the HAML direction. The cleaner and simpler the better.
    —trice

  6. Permalink to comment#

    I’m sticking with HTML 4.01 Strict because unless you configure your server to serve XHTML as application/XML, browsers treat XHTML as regular ol’ text/HTML. Besides, I’d like to think I’m long past the point when an ‘x’ sounded cool. :)

  7. I’ll be honest… who cares? IMHO as long as the code works and displays properly on most modern browsers (screw IE6) then you good to go. Validation is one of those things I basically think well its a pain in the ass but its almost a necesity especially if your selling web design. I try to keep all my code clean in XHTML 1.1 Transitional and soon I may move on to attempting strict :P

  8. Permalink to comment#

    XHTML Strict 1.0 for work/personal use, when I’m able to do so.

    Sometimes work forces you to use stricter (1.1) or looser markup (even Transitional 4.01!), depending on the backend system you’re using and who the target is (for instance, a web tool created for you and some colleagues doesn’t have to validate as long as it works).

    What’s most important is to point this out to clients, and tell them about what the difference in DOCTYPE means. If a client don’t give a rat’s ass about web standards, you should try to convince them that they should, as it would improve their quality outwards.

    A lot of people don’t even know that blind people are also using the Internet, and they (the people, not the blind) can’t care less about accessibility.

  9. Felix Jimenez
    Permalink to comment#

    As Rob and Jesse stated the problem with XHTML is the way it’s served. XHTML documents are supposed to be served with the application/xhtml+xml MIME type. Most people don’t know that, slap the XHTML doctype in their documents and call it a day. Despite that doctype your site is parsed by browsers as regular old HTML 4.01 not XHTML.

    IE currently doesn’t support the MIME type for XHTML, so it won’t render XHTML documents served properly. Browsers like Firefox do, so you’d need to serve as text/html to IE and any other browser that doesn’t support XHTML and application/xhtml+xml to ones that do.

    Most people who use XHTML use it as if it were HTML. There’s nothing stopping you from nesting tags properly, quoting your attributes, sticking to lowercase, etc, in HTML. You should be doing that anyway. So I’d say unless you can find a real reason for you to use properly served XHTML, just stick with HTML 4.01.

  10. Great topic, and one that I don’t see discussed too often. I personally use XHTML transitional for every site I design. Why? I guess because that’s what I learned to write in. I’m pretty meticulous about code, so XHTML works for me just fine.

    After reading articles like this, it does make me realize that there’s a lot more for me to learn and understand.

  11. Permalink to comment#

    IE 6 and IE7 do actually support xhtml. You just have to trick them into doing it via application/xml and an xsl file. See my demo here for how to do that.
    Regardless I still only use HTML 4.01 strict just because xhtml leaves a bad taste in my mouth.

  12. Reasons for HTML 4:
    Easy to write
    Easy to validate

    Reasons for XHTML:
    Newer recommendation
    Supports new technologies by virtue of XML namespaces
    Encourages good quality pages (separation of structure and presentation)
    Encourages strong typing (lower case, closed tags etc)
    Can be parsed as XML and used elsewhere

    New technologies being things like RDFa and ARIA.

    Really this is the way I look at it and realize that there is no reason to create websites in a format that is outdated – XHTML is backwards compatible if that’s an issue.

  13. Permalink to comment#

    I’ve been researching on this topic extensively for the past few years. As of now, there’s VERY little benefit of using XHTML. As others have mentioned, IE(even IE8) won’t support application/xhtml+xml. Also, even for browsers that do support xhtml as the proper mime type, what validates as xhtml+text won’t necessarily validate as xhtml+xml.

    I still use XHTML Strict doctype. The indirect benefit is it keeps me in check to write proper code. That’s all.

  14. Paul Wilkins
    Permalink to comment#

    I am in agreement with Jin.
    The XHTML vs HTML faq covers the topic very clearly. Internet Explorer does not currently sopport any XHTML at all.

    This means that if you write your code as XHTML, you can not take advantage of any of the benefits of XHTML because you must ensure that everything you code as XHTML can also be understood as HTML 4 so that IE is able to understand as well.

    Because of this limitation, it’s better to stay with HTML 4 (while keeping coding practices for XHTML firmly in mind) until users of IE are capable of enjoying the benefits of XHTML as well.

  15. taotsu-pro
    Permalink to comment#

    Hm… I have been thinking very very long about this. during first learning and now in 3 years of devlopment.

    I actually would love to write XHTML 1.1!! I once did for fun. The code looks soooooo lovely, its not sooo hard to do and its interesting to think about how to use the modularisation properly.

    On the downsite, if you want to produce pages that can be viewed properly, also on Mobile devices, etc. than HTML 4.1 is the better choice. Nevertheless, since XHTML can be served as HTML I prefer doing so. I wont get too lax, I can be sure IE displays the code (even in Version 5, as far as I tested it) and I can, if I write more complex pages (for example in an CMS) easier transist pages onto REAL XHTML.

    Since I live and work in Japan, internationalisation is also an issue (see ALA → http://www.alistapart.com/articles/worldgrowssmall/ which I found highly enlightening, also → http://www.alistapart.com/articles/understandingprogressiveenhancement).
    In the end its a personal decision, but also commercial decision i believe. The company I work for uses a system that has been build in HTML 4.01, no way to change that, no way to write clean code (for commercial reasons). I personally always write XHMTL 1.0 trans, so I can serve it as HTML without feeling bad.
    Well, make up your minds ^-^

  16. Permalink to comment#

    I’ve been using XHTML 1.0 Strict since I became aware of validation and the importance of clean code (which, embarrassingly enough, wasn’t all that long ago, so I’m still retrofitting some of my sites).

    I don’t think there’s really a difference at this point, so long as you’re writing pretty code. :) I would argue, however, that XHTML will be the standard in the future, so it doesn’t hurt to look ahead when building websites, especially since, like Joshua said above, XHTML is backwards compatible.

  17. I must say i still find these doctypes a bit confusing. We use HTML 4.01 transitional on our backend services but front end client sites are XHTML 1.0. Our backend site uses iframes so as i understand HTML 4.01 transitional is the best one which allows for iframes?

  18. @Jason,

    yo its true, XHTML might vanish one day. Its definitely a good idea to take a look at HMTL 5, even though I think there doctype is ugly— (<!DOCTYPE html>)
    ^-^

  19. Miles Johnson
    Permalink to comment#

    No one knows what they are talking about in these comments. Everyone who says “oh xhtml because its cleaner and more up to date” have no clue. You can write HTML 4.1 exactly like XHTML (without having to do />, less work!).

    Felix Jimenez is the only one who knows what hes talking about.

  20. XHTML strict all the way.

  21. Anders
    Permalink to comment#

    This means that if you write your code
    as XHTML, you can not take advantage
    of any of the benefits of XHTML

    What exactly are the benefits of using XHTML? Could anybody explain that in a non tech language?

  22. Permalink to comment#

    I’m thinking of going back to HTML 4.01 for all of the technical reasons there are NOT to us XHTML 1.0. AT the time I was learning web development, XHTML 1.0 was all the rage. The W3C even said there would be no new versions of HTML ever and that XML was going to be the future. So I started off coding in HTML 4, then quickly switched to XHTML strict when it was the new thing.

    Now we have HTML 5 and XHTML 2 going on.

    But what I do like about XHTML is that it forces the developer to close their tags and the syntax rules are simpler and more consistent. However, these are the only reasons to support XHTML 1.0, since if it was served as XML and not HTML, practically no one would see it (thank you IE).

  23. Are there resources on how to right code for each of the doctypes. I must be honest that I have just played with doctypes and never really understood how one is making a difference over another. Sounds to me also that if XHTML is backwards compatible and the direction that things are heading in then shouldn’t we just learn that and let html die out when it finally does?

  24. Permalink to comment#

    As it’s been stated, XHTML isn’t even parsed as XHTML in Internet explorer and most people don’t even take advantage of it’s benefits over HTML. 99% of the websites coded in XHTML could be coded in HTML 4.01 and still work.

    Just to reiterate, Internet Explorer does NOT SUPPORT XHTML!!! (It doesn’t support the “application/xhtml+xml” mime type.

    Most people overlook the simple fact that XHTML is XML, HTML is not – people thing HTML is XML because it looks similar… they’re wrong!

    Apart from the obvious differences in syntax the only REAL benefits offered by using XHTML is the potential integration of other XML namespaces – nobody really takes advantage of this due to the massive lack of XHTML support in IE6/IE7.

    XHTML 1.0 is the official recomendation of the W3C – There is NO point in using XHTML 1.1 – all it offers are some slight variations from a syntax position. (oh and it has ruby annotations… nobody uses these!)

    The fact is that, if not for everyone jumping on the bandwagon, XHTML 1.0 would be MUCH less popular nowadays. HTML 4.01 is still perfectly fine and I prefer coding in it… My personal sites are in XHTML because I’m lazy and cannot be bothered to get rid of the all the self-closing tags in WP CMS!

    Most people that think they’re using XHTML actually are not. Since they’ve serving their pages as ‘text/html’ that’s how they’ll be parsed…

    @Chris – Where did you hear that IE8 supports XHTML? AFAIK it is the same as IE7 and doesn’t support the “application/xhtml+xml” mime type.

    If anyone honestly believes that coding in XHTML 1.0 is better than HTML 4.01 for everyday website creation then I’d love to hear your argument… I’m intrigued!

  25. Permalink to comment#

    If you’re serving your XHTML as Text/HTML rather than XHML (go check your code) then you may as well be using HTML 4.01 instead. While there are benefits in using proper XHTML, there’s absolutely no benefit in using XHTML as Text/HTML… in fact I consider it invalid HTML 4.01!

    FWIW I used to markup my sites in XHTML 1.0 Strict as true XML, but the draconian error handling (which I could handle, but clients and other developers couldn’t) and the lack of support from IE turned back to the far more suitable HTML 4.01.

  26. Permalink to comment#

    Oh btw it’s HTML 4.01 strict, none of this transitional nonsense.

  27. Permalink to comment#

    @John @Jason

    I’d love to know how using XHTML Strict (as text/html) helps you write proper markup? There is no reason at all you couldn’t write clean, valid and semantic markup using HTML 4.01 strict… none at all. As I’ve mentioned above if you serve XHTML as text/html then you are actually creating sites with invalid HTML 4.01.

  28. At link text, we use XHTML 1.1, with the correct CSS, our website is compatible with IE6/7, Firefox 3 and Safari 3. We like clean code.

This comment thread is closed. If you have important information to share, you can always contact me.

*May or may not contain any actual "CSS" or "Tricks".