I see a bunch of up-voted answers here that are making incorrect assumptions about how browsers work. So let me give my 2 cents on the matter.
First of all, why does XHTML exist?
From the horse's mouth:
a two-day workshop was organised to discuss whether a new version of HTML in XML was needed. The opinion at the workshop was a clear 'Yes': with an XML-based HTML other XML languages could include bits of XHTML, and XHTML documents could include bits of other markup languages. We could also take advantage of the redesign to clean up some of the more untidy parts of HTML, and add some new needed functionality, like better forms.
In short, XHTML was created for two reasons:
- To allow mixing other content (like mathml and svg) in the same document with clear formatting rules.
- To extend and clean up HTML.
Making things easier to validate was not a design goal, and also not something that was necessary because HTML4 validators exist and are comprehensive.
Is XHTML easier to parse for browsers?
Yes and no. XML is easier to parse than HTML tag soup, but, unless you use an xhtml+xml or application/xml mime type for your XHTML page, browsers parse it using the HTML parsing engine. However, if you do use xml mime types, IE chokes on your content. This behavior is explained on the IE blog. There is no difference in how browsers treat XHTML and HTML if you are serving it with a mime type of text/html!
Yes they do! You lie!
Indeed they do, but only because of the doctype. Browsers use doctypes at the top of HTML documents to determine whether they should use standards mode or quirks mode (= bugs mode). All valid XHTML documents happen to include a doctype that triggers standards mode. However, in HTML you can get the same result by including "<!doctype html>" at the top of your page.
So are you saying XHTML has no purpose?
Not at all. XHTML has many advantages:
- It can be transformed using XML tools, like XSLT
- It can be parsed more easily in server-side code
- It can integrate custom markup while still passing a validation test
So, I should use it then?
As always, the answer is "it depends".
- Server-side, possibly useful. If you want to have the server-side advantages of XML, you want to be using an XHTML variant, whether that is XHTML1 (HTML4 serialization as XML) or XHTML5 (HTML5 serialization as XML).
- Client-side, not useful. I would highly recommend avoiding serving your users an XML mime type. XML parsing doesn't blend with graceful error handling, producing only an "XML parsing error" instead of a document if you have any markup issue in your page. Unless you never write bugs, you will need graceful error handling.
What about HTML5? Does it compete with XHTML?
No it doesn't. HTML5 has two serializations, one as HTML, and one as XML. The benefit is that both now have strict parsing rules. You will get predictable behavior in all browsers regardless of the approach you use. However, HTML5 parsed as HTML has the benefit of graceful error handling. That's why I prefer that approach. As always, YMMV.