Choosing HTML or XHTML

Robert Nyman’s post HTML or XHTML? discusses some of the differences between HTML and XHTML. The information may help you make an informed decision next time you’re in a position to choose between using HTML and XHTML.

I agree with Robert here: using a Strict doctype is far more important than whether you use HTML or XHTML. Strict doctypes will help you separate content and structure from presentation, and will trigger full standards mode in web browsers that support doctype switching.

So, what do I use? It depends. 456 Berea Street is currently HTML 4.01 Strict. I used to use content negotiation to send XHTML 1.0 Strict as application/xhtml+xml to browsers that support it, and HTML 4.01 Strict as text/html to others. For various reasons, all browsers now get the latter.

Posted on November 4, 2005 in (X)HTML, Quicklinks

Comments

  1. I agree with you. I’ve been using HTML 4.01 again since a few months. IMO there just aren’t any advantages to use XHTML.

  2. I figure the main advantage is that it doesn’t hurt to move to xhtml…even if the mime type serves the page as html. At the least it will be supported at a latter point in time. Roger, I’m just glad you’re not the type that outcasts those who don’t use one or the other. They both work and they get the job done.

  3. This is a no-brainer: xhtml!

    One has future-proofing web-standards being considered…and the other is the past.

  4. I’m working on a project at work in which I can (hopefully) achieve full strict compliance except for one tag which must be inside a tag at the bottom of the page, used for page tracking.

    I’m debating whether I should use a transitional doctype simply for the sake of this one image, which is not allowed inside in the strict doctype.

    Should I change doctypes because of this image, or invalidate every page built on the template because of the illegal image?

  5. I see it mostly as a non-issue. My preference is xhtml 1.0 served as text/html for the time being. The fact that I like well-formedness is one reason. Old programmers habits die hard, and HTML Tidy is always around to guard against “human bugs”.

    Strict/transitional is a matter of choice. I know the difference, and often force HTML Tidy to leave my code at transitional, even though it is confirmed as strict to begin with.

    I also like to treat IE6 in quirks mode, so the xml declaration comes handy - especially now that I know that IE7 will go into strict mode with that declaration present.

  6. Matt: Uhm, re: future proofing. I do believe they’re working on an HTML 5, which means that XHTML and HTML will be holding hands as they go forward into the future. So really, no, it’s not a future proofing issue to go with XHTML. :-(

  7. Ara: It’s an issue at present as 5 doesn’t exist yet and xhtml is more future friendly than html 4 - I’m talking about the here and now - get it right! :D

    Anyway - as xhtml beats html 4 with a big stick, and isn’t a great deal more different to implement, it really makes the choice between the two obsolete. If xhtml was dramatically hard to use and bothersome then I’d say stick with the html, but it isn’t.

  8. Slackers! My site uses XHTML 1.1!

    Seriously though, I see nothing wrong with using HTML 4.01 or XHTML 1.0 — whatever is needed for that particular project.

  9. November 5, 2005 by Roger Johansson (Author comment)

    Dustin: Yeah I don’t like the idea of picking on anyone who has made an informed choice between HTML and XHTML. Both work.

    Matt: In my opinion, XHTML is easier than HTML. The trouble comes when you want to use XHTML properly and serve it as application/xhtml+xml. As soon as a well-formedness error occurs, the document breaks. And you can’t always have 100% control of what ends up in the markup. It is especially difficult in large projects where the final output often consists of content from several different systems, not all of which are web standards-aware.

    Jordan: Hehe. I sure hope you aren’t sending that XHTML 1.1 as text/html - only XHTML 1.0 allows that.

  10. November 6, 2005 by Maarten van Soest

    I’m curious and like to hear other opinions. What are your various reasons Roger?

  11. November 6, 2005 by theUg

    For instance, would the popular nowadays attribute rel=”nofollow” be out of place in HTML 4?

  12. November 6, 2005 by theUg

    Apparently not (knocking meself on the head with validator). Anyhow, then, what are the reasons. So far we’ve seen loads of “why not to”, but never a clear “when to” use XHTML.

  13. November 6, 2005 by Roger Johansson (Author comment)

    Marten: The two main reasons I have for switching from XHTML to HTML for this site are:

    • When you send XHTML as application/xhtml+xml you must make sure that all markup is well-formed. And that includes comments. I always had an uneasy feeling about that, and kept worrying that errors would sneak through and break the site in Gecko and Opera.
    • Google AdSense targeting doesn’t work properly when you use an object element to include an HTML 4.01 Transitional document containing the ad code.

    Yes, I could have just removed the content negotiation and started serving XHTML 1.0 as text/html. But since my content negotiation script converts XHTML to HTML for browsers that don’t handle application/xhtml+xml it was easy to tell it to do that for all browsers.

    The whole site is still XHTML before it has passed through that script, so should I decide to switch back to XHTML again I just need to open a php file and change a setting.

  14. On my own site, I use XHTML 1.1 (and send 1.0 Strict as text/html to browsers that don’t support application/xhtml+xml — namely IE/Win 6.0).

    Of course I can do this only because I have total control over the content of the site. And the primary reasons for this decision are to promote and advocate the correct use of XHTML, and also to demonstrate you can use 1.1 with plenty of features and still have it validate across the board. I have hundreds (at least) of pages and they are all 100% valid markup.

    For a client or employer, this might not be practical. But that’s why we have different document types — chose one that’s appropriate for your project.

  15. I choose XHTML, mainly because when I have to do editing on the server I have to use Emacs and then I use NXML-mode which validates and autocompletes my code on the fly.

    So I guess i’m just lazy but for once I think it’s paying off… ;)

  16. Well, I’m a total nOOb to all this stuff. can someone give me a quick rundown of when to use html or xhtml,(I usually just use xhtml strict 1.0) and when to send as text/html or application/xml, etc? or point me to some material that i can read up on it about. thanks alot.

  17. Jake, the short rundown is as follows:

    http://www.w3.org/TR/xhtml-media-types/#summary http://www.w3.org/International/articles/serving-xhtml/

    Plus you have to be careful of using Scripting with proper XHTML in most cases Strict HTML 4.01 is fine.

Comments are disabled for this post (read why), but if you have spotted an error or have additional info that you think should be in this post, feel free to contact me.