tags:

views:

122

answers:

3

What we should opt ? XHTML or HTML 5 ?

+5  A: 

If you've already written your website, then don't bother changing it. If you haven't written it already, then just use HTML5 (DOCTYPE html). The main difference is that you get additional features with HTML5 (although you don't necessarily need to use them), while XHTML forces you to format your HTML in an XML-compatible way (although you can format your HTML5 code in an XML-compatible manner, also). It is a common misperception that using an XHTML doctype and adding an XML declaration to your XHTML code (e.g. <?xml version="1.0" encoding="utf-8"?>) is sufficient to make it XHTML. In fact, this is not the case... it will only be interpreted as XHTML if it is returned using the appropriate content-type.

Advantages to HTML5

  • More features (canvas, localstore, etc.)
  • More lenient (doesn't have to be 100% XML)
  • Predictable failure (behaves in well-defined ways when improperly formatted)

Advantages to XHTML

  • More strict (forces you to use 100% XML)

Disadvantages to XHTML

  • Fewer features
  • More strict (if it's not 100% XML, it will break)
  • May not actually be XHTML (if you forgot to use the correct content-type)

XML strictness
The only advantage I can think of for XHTML is that it forces you to make the document fully XML-compatible. However, you can still make HTML5 100% XML-compatible, it just doesn't force you to do that. If you want to be stringent with yourself, just run it through an XML parser/validator yourself, and you can get the same level of stringency while at the same time using HTML5.

Michael Aaron Safyan
This is both wrong and muddled. Most notably, HTML5 and XHTML are not alternatives. A page can be XHTML **and** use HTML5 features such as canvas.
Alohci
@Alohci, not with XHTML 1.0.
Michael Aaron Safyan
Thanks alot Michael...:)
Aneesh
Neither the OP nor you in your answer mention the XHTML version. In any case, browsers* implement XHTML, not a particular version of XHTML. (* IE, prior to IE9 platform preview, doesn't implement XHTML at all, of course)
Alohci
@Alohci, that's correct... however, the DOCTYPE does specify a particular version.
Michael Aaron Safyan
@Michael. Not sure what you're implying by that. The DOCTYPE specifies a particular **DTD** which may be used for validation purposes. When a page is served with an XML mime type, the DOCTYPE has no effect on the browser at all and may simply be omitted.
Alohci
+ When a page is served with a text/html mime type, the DOCTYPE has only affects quirks vs limited quirks vs standards mode.
Alohci
@Alohci, that is also correct. Nevermind.
Michael Aaron Safyan
A: 

The question presents a false dichotomy. HTML5 will have both HTML and XML (XHTML) serializations. So there are really two questions: HTML4 vs HTML5 and XHTML vs HTML. Additionally, XHTML can be served with the text/html mime type, where it mostly behaves like HTML.

For the first question, HTML5 isn't complete yet, but you may be able to use some features now. Use whatever constructs are supported in enough of your targeted browsers to be worthwhile and use graceful degradation/ progressive enhancement to support the rest.

For the second question, I prefer HTML to XHTML and I explain my reasoning here. For the actual differences, I would refer to the link SaC provided for the differences in version 5 and this document for the difference between HTML4/XHTML1.0.

Casebash