2

I'm sure everyone here knows that we cannot serve the pages with the correct MIME type (application/xhtml+xml) for XHTML without breaking IE compatibility, and that any content served with text/html will be parsed as HTML by any browser out there. So if the content is not parsed as XML.

I use a xhtml doctype only for one reason: it helps me find “errors” in my markup in a more stricter way compared to html. Even if my documents are served as text/html

Is there any other benefit to use XHTML 1.0 Strict with content="text/html; over HTML 4.01 strict at all? At present or and in the future.

  1. if i'm already writing well formed valid HTML 4.01 strict and
  2. not want to use any extra XHTML features (SVG, Docbook, MathML, OFX, etc),
  3. never going to manipulate my XHTML to XSL(T)
  4. never goint to server document as application/html+xml
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852
  • this is a duplicate: http://stackoverflow.com/questions/867498/at-the-end-of-the-day-why-choose-xhtml-over-html – Mark Elliot Jan 24 '10 at 03:32

3 Answers3

6

None. You don't get any of XHTML's benefits. As far as the browser is concerned, it's getting weird HTML, not XML. If you want to get the benefits of XML, like extensibility and the stricter parser (if that's a benefit), you have to serve your page as application/xhtml+xml, and IE won't support it. Not to mention XHTML 1.0 is incompatible with 2.0, while HTML will always be future proof.

You may want to read this, among many others. In short, only use XHTML if you know you need to, otherwise it's useless.

XHTML also doesn't necessarily mean that the browsers will adjust to standards. Don't worry about the Standards vs Quirks mode stuff, it's something that has be mantained for backwards compatibility. When a browser encounters a page with a doctype (any doctype, HTML or XHTML), it will try to render it according to standards. It doesn't mean that it will render it just like the W3C says, it just means that it will try to (and maybe not succeed).

Javier
  • 4,552
  • 7
  • 36
  • 46
  • Is the IE only browser which do not support application/xhtml+xml, and does no ie version support application/xhtml+xml , IE 7, 8 ? or only IE6 doesn't support – Jitendra Vyas Jan 24 '10 at 03:36
  • No version of IE supports it: http://en.wikipedia.org/wiki/Internet_Explorer#Features – Javier Jan 24 '10 at 03:39
  • Not all doctypes cause browsers to render in standards mode. Here (http://dev.w3.org/html5/spec/syntax.html#quirks-mode-doctypes) is a list of doctypes that don't. – Alohci Jan 24 '10 at 12:19
1

XHTML comes with default style rules (css), at least to some degree. And also some strict rendering rules. Any browser implementing XHTML doesn't have much leeway in how to present things, so in making an XHTML document, developers may find that their document renders the same in most browsers (although there are still some minor problems, especially with IE).

In later years this has improved greatly, and most XHTML documents' styles render the same way in "all" browsers.

You may also have heard of "standards mode" and "quirks mode". Quirks mode is when (mainly IE) takes into account all the wrong things it's been doing in previous versions, and renders pages the way it used to, so it will render the way it was intended THEN. Standards mode is a strict mode, which uses only standardized rules. This breaks some older pages, but lightens the load for many developers.

Tor Valamo
  • 33,261
  • 11
  • 73
  • 81
  • Although XHTML doesn't have much leway in how to present things, IE won't render it, so the point is more or less moot. – Javier Jan 24 '10 at 03:39
  • you mean HTML document don't styles render the same way in "all" browsers? – Jitendra Vyas Jan 24 '10 at 03:39
  • Of course they don't. Maybe a very simple one will, but in many cases you'll have to test against different browsers and adjust the CSS and stuff. IE is especially quirky with this. – Javier Jan 24 '10 at 03:41
  • My question is XHTML 1.0 strict vs. HTML 4.01 strict, so u mean HTML 4.01 strict do not render page in standards mode, only XHTML can? – Jitendra Vyas Jan 24 '10 at 03:43
  • @Javier Badia - but this site using HTML and looking same in all browsers – Jitendra Vyas Jan 24 '10 at 03:44
  • The point is that what each browser calls "standards mode" doesn't adjust to the same standards as all the others. Standards/quirks mode is a remainder of compatibility problems with sites designed for IE 5 or lower (I think). Just because IE is rendering in standards mode doesn't mean that it follows the W3C standard. – Javier Jan 24 '10 at 03:46
  • @Jitera: about your second point: Yes, because with some tweaking it's possible to make it look the same everywhere. But it can be hard sometimes. What I meant is that until you fix it, the layout can be different between browsers. – Javier Jan 24 '10 at 03:47
  • "IE won't render it". Sure IE will render XHTML. You just gotta put a doctype in there, like grown ups do. – Tor Valamo Jan 24 '10 at 03:48
  • @Javier Badia - You mean HTML 4.01 strict render page as a IE's Standard mode not W3C Standar and XHTML Strict render page as a W3C's Standard mode? – Jitendra Vyas Jan 24 '10 at 03:48
  • @Tor Valamo: I was under the impression that IE didn't work with XHTML served as `application/xhtml+xml`. – Javier Jan 24 '10 at 03:52
  • @Javier Badia - ok so this is the pros over HTML, as you are saying in your 4th comment, XHTML 1.0 Strict with content="text/html; would be more is cross browser compatible than HTML 1.0 Strict without tweaking. – Jitendra Vyas Jan 24 '10 at 03:56
  • @Javier - That might be true. Though I always count on xhtml being .html files, thus being served as text/html... – Tor Valamo Jan 24 '10 at 03:58
  • @Jitendra: XHTML as text/html is techincally wrong. It doesn't affect cross browser compatilibility. I suggest you read the site I linked to and then do some Googling to find out how validity and such things work, because it's complicated to explain in these comments. – Javier Jan 24 '10 at 03:59
  • @Tor Valamo: Then it's being parsed as HTML, not XHTML, so it won't make a difference. – Javier Jan 24 '10 at 04:01
  • It may be technically wrong, but it's how it works, since a static server can't tell that a .html file contains xhtml... And I don't think it's fair to count on having a meta content tag in every document. And browsers render it correctly when it's text/html and xhtml doctype, so I'm not complaining. – Tor Valamo Jan 24 '10 at 04:02
0

XHTML consists of all the elements in HTML 4.01, combined with the strict syntax of XML.

Derek Adair
  • 21,846
  • 31
  • 97
  • 134
  • What is practical benefit of "strict syntax of XML"? – Jitendra Vyas Jan 24 '10 at 03:32
  • 2
    None, really. It forces you to write well formed code, but if you care about that you can do it in HTML. And if you have user-submitted content, a sinalge malformed tag will bring your whole page down. – Javier Jan 24 '10 at 03:35
  • Because XHTML documents need to be well-formed, they can be parsed using standard XML parsers—unlike HTML, which requires a lenient HTML-specific parser – Derek Adair Jan 24 '10 at 03:35
  • @Javier Badia- is well formed document means W3C valid document? – Jitendra Vyas Jan 24 '10 at 03:41
  • @Jitendra: Nope. See the link I gave in my answer, I think the difference is epxlained somewhere in that site. – Javier Jan 24 '10 at 03:44
  • @Javier Badia - Can u explain more of this line "And if you have user-submitted content, a sinalge malformed tag will bring your whole page down." – Jitendra Vyas Jan 24 '10 at 03:46
  • @Jitendra: I think the link I gave says something about it, but imagine this: you have a blog. You can have user comments, and allow some XHTML in them. If an error (for example, a br tag without the closing slash) manages to get through to your site, the browser will refuse to render it at all. See my link, section "Benefits of XML". – Javier Jan 24 '10 at 03:51
  • It has however a benefit when using a XML based tool to generate/parse/serve webpages, like as in component based MVC frameworks. --This was told you several times before, Jitendra. – BalusC Jan 24 '10 at 06:04