Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Practical Difference between XHTML, HTML, AND XML

So here's what I understand (please correct if wrong) :

  • HTML5 is the newest version (or at least soon to be released) of HTML and contains features that XHTML does not yet have
  • XHTML served as MIME type text/html is equal to HTML for the purposes of rendering
  • Converting from text/html to application/xhtml+xml is difficult because it's not HTML
  • XML is not compatible with HTML

So my question is, what does XHTML have to do with HTML besides the usage of tags? What is the practical purpose of using XHTML over XML, or is there none?

like image 785
waiwai933 Avatar asked Jan 22 '10 04:01

waiwai933


2 Answers

Yes, HTML5 will have features (nd even elements/tags) which XHTML does not yet have. It will also reintroduce some tags from HTML4 which were removed for XHTML. (iframe, is one of them, I think)

If you want to know about the differences between HTML4/XHTML and HTML5, read the wikipedia entry on HTML 5: http://en.wikipedia.org/wiki/HTML_5#Differences_from_HTML_4.01.2FXHTML_1.x

However, no, XHTML is not equal to HTML for the purposes of rendering. http://hixie.ch/advocacy/xhtml

XHTML is more XML than it is HTML. It essentially uses (most of) the elements ('tags') from HTML while respecting the stricter grammar and semantics of XML.

It is not equal to HTML4 for the purposes of rendering. If you use a mime type of XHTML - since it is XML - you can end up with nasty parse errors if you do it wrong:

A nasty XHTML parse error

... but despite this problem using XHTML can result in more consistent behavior between browsers than HTML4; since HTML4 is not as strict, browsers try really hard to interpret ambiguous markup, and the browser's developers end up with some freedom to choose how these ambiguities are treated. This leads to inconsistencies, but with XHTML - being XML - the browser is supposed to refuse to render the page at all should it be ambiguous.

XHTML can lead to problems with older browsers though, especially with empty elements (self-closing tags) such as <br />; an old browser won't know what to do with the / and might think its part of the tag name and then you lose your line break.

Lastly, I don't know what you mean by "Converting from text/html to application/xhtml+xml is difficult because it's not HTML" but I encourage you to check out the book "Refactoring HTML" by Elliotte Rusty Harold... it seems to be a 300+ page answer to the question ;)

like image 76
Richard JP Le Guen Avatar answered Nov 15 '22 12:11

Richard JP Le Guen


HTML5 is the newest version (or at least soon to be released)

Draft. Unstable. Subject to change. Not going to be released soon.

XHTML served as MIME type text/html is equal to HTML for the purposes of rendering

More or less. Writing HTML compatible XHTML is more work than writing HTML or XHTML, and doesn't let you use any of the interesting bits of XHTML.

Converting from text/html to application/xhtml+xml is difficult because it's not HTML

Converting from HTML to XHTML is actually pretty trivial. Tidy can do it for lots of documents (including all valid HTML documents).

XML is not compatible with HTML

It would be truer to say that HTML isn't XML.

So my question is, what does XHTML have to do with HTML besides the usage of tags? What is the practical purpose of using XHTML over XML, or is there none?

The advantage of using XHTML over XML is roughly the same as using a car over a pile of metal and plastic. XML is a toolkit for building markup languages.

The advantage of using XHTML over HTML is that you can mix different markup languages into one document, so (for example) you could have an XHTML+SVG+MathML document. This requires the client to support all the languages involved (or for the unsupported ones to gracefully degrade).

Unfortunately, this is impractical for most projects since Internet Explorer…

[doesn't support XHTML]

like image 39
Quentin Avatar answered Nov 15 '22 12:11

Quentin