At The End of The Day, Why Choose Xhtml Over HTML

At the end of the day, why choose XHTML over HTML?

You should read Beware of XHTML, which is an informative article that warns about some of the pitfalls of XHTML over HTML.

I was pretty gung-ho about XHTML until I read it, but it does make several valid points. Including the following bit;

XHTML 1.x is not “future-compatible”. XHTML 2, currently in the drafting stages, is not backwards-compatible with XHTML 1.x. XHTML 2 will have lots of major changes to the way documents are written and structured, and even if you already have your site written in XHTML 1.1, a complete site rewrite will usually be necessary in order to convert it to proper XHTML 2. A simple XSL transformation will not be sufficient in most cases, because some semantics won't translate properly.

HTML 4.01 is actually more future-compatible. A valid HTML 4.01 document written to modern support levels will be valid HTML 5, and HTML 5 is where the majority of attention is from browser developers and the W3C.

Future compatibility can be huge when working on some projects. The article goes on to make several other good points, but I think that may have stood out the most for me.

Don't mistake the article for a rant against XHTML, the author does talk about the good points of XHTML, but it is good to be aware of the shortcomings before you dive in.

What are pros to use XHTML 1.0 strict with content=text/html; over HTML 4.01 strict?

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).

What's the need for XHTML?

I am actually writing this to ask why the above three posts which speak about browser-consistence and well formed html have been voted down?

As it is known HTML is a industry standard. Browsers are implemented so that they render the marked up content as described in the HTML standard. Unfortunately there are areas that have not been well defined in HTML: what happens if user forgot a closing tag or what to do if a referred image is not found? some browsers use the 'alt' tag to have a place holder text item and some browsers display the 'alt' tag as a tool tip. The famous 'quirks' mode of browsers is a result of this lack of clarity. Because of this, it became quite possible that the same web page would display differently on different browsers.

Also as HTML usage grew there was one more problem: it was not extensible - there was no way to add user-defined tags.

XHTML solves the above problems:

  • adopt XML to provide extensible tags.
  • provide a 'strict' standard for web browsers

XHTML has well defined rules about the structure and these can be programatically enforced. Check the various online "XHTML Validators". They will tell if your XHTML is well formed or not (and highlight the problem areas). Because of these strict rules your page is more or less guaranteed to look the same on all browsers implementing XHTML.

[note] if you want to verify the above, please refer to the text "Head First XHTML and CSS"

The Future: XHTML 2.0 vs HTML 5

At its core, the question boils down to this: what do you want to do with the markup? I'd go on, but this has kinda been discussed to death already...

Please see:

  • At the end of the day, why choose XHTML over HTML?
  • Why are (X)HTML 5 and XHTML 2 separate standards?

Which doctype do you use when writing webpages?

I use the HTML5 doctype:

<!DOCTYPE html>

Because XHTML does not work on the web and doctype is essentially only good to trigger the standards layout mode, which the above construct does very well in every browser.

Do I need a / at the end of an img or br tag, etc.?

The / is only required for XHTML & XML.

If you're using a HTML5 doctype, then there's no need to terminate self-closing tags in this way.

This applies to <img src="img.png" />, <br />, <hr /> etc.

I.e. Just use <img src="img.png">, <br> and <hr>.

If you need an empty element (like a div), don't use <div />, instead use <div></div>. This is important since in HTML5, the slash is ignored and <div /> is interpreted as <div> without a closing tag.

Why put an XHTML doctype declaration on HTML files? What does that do?

Why put an XHTML doctype declaration on HTML files? What does that do?

All that does is tell markup validators that they're about to validate an XHTML document, as opposed to a regular, SGML-rooted, HTML document. It describes the content, or more specifically the markup that follows, but nothing else.

Why are people doing this? What do they hope to achieve? Why not reserve the XHTML doctype declaration for actual XHTML files?

Or am I missing something?

Kind of. What actually happened was that people weren't aware that just putting an XHTML doctype declaration on top of an HTML document didn't automatically transform it into an XHTML document, although admittedly that was what everybody was hoping for.

You see, most web applications out there aren't configured to serialize XHTML documents as application/xhtml+xml properly, instead opting to serve pages as just text/html. (It's typically because of the .html file extension more than anything else, really; generally speaking, servers do correctly apply application/xhtml+xml to documents with .xhtml or .xht as the extension, but only static sites that actually make use of the file format will benefit from this.) That leads browsers to decide that they received a regular HTML document, and so that tag soup parsing nonsense we've all come to know and love inevitably ensues.

Note that it doesn't matter even if you have a meta tag like this on your XHTML document:

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

Browsers will ignore that, and only look at the actual HTTP Content-Type header that was sent along with the XHTML document.

To make matters worse, Internet Explorer, being the most-used browser in the past few years in XHTML's heyday, never properly supported the application/xhtml+xml MIME type before version 9 was finally released: instead of parsing the markup, constructing the DOM and rendering the page, all it would do was ask for a file download. That doesn't make a very usable XHTML page!

So, guess what we all had to live with until HTML5 became cool?

This, along with things like IE6 going quirky on pages with the XML declaration before the doctype declaration, is also one of the biggest factors leading to XHTML's downfall (along with XHTML 1.1 never gaining widespread usage, and XHTML 2.0 being canceled in favor of HTML5).

Uses for the '' entity in HTML

It is impossible, and unnecessary, to know the motivation for using " in element content, but possible motives include: misunderstanding of HTML rules; use of software that generates such code (probably because its author thought it was “safer”); and misunderstanding of the meaning of ": many people seem to think it produces “smart quotes” (they apparently never looked at the actual results).

Anyway, there is never any need to use " in element content in HTML (XHTML or any other HTML version). There is nothing in any HTML specification that would assign any special meaning to the plain character " there.

As the question says, it has its role in attribute values, but even in them, it is mostly simpler to just use single quotes as delimiters if the value contains a double quote, e.g. alt='Greeting: "Hello, World!"' or, if you are allowed to correct errors in natural language texts, to use proper quotation marks, e.g. alt="Greeting: “Hello, World!”"



Related Topics



Leave a reply



Submit