tags:

views:

1277

answers:

10

Hi all,

I'm wondering if I should bother at all about the markup language, as long as i produce valid markup.

I've read articles that point out HTML is the best choice and they come directly from the horse's mouth (the browsers implementors!):

Other articles, by James Bennet, make another point that if you're not serving XHTML as XML then you don't want XHTML but HTML.

So i thought that if i wanted to trigger Standard Compliant Mode i should just use HTML strict validation. But that's not the case anymore with at least the most modern browsers (aka everything but IE6): if you have valid XHTML Strict you still trigger Standard Compliant Mode, hence, as long as i produce valid markup, why bother?

A: 

I would go for xHTML, mostly because the code is cleaner and easer to maintain.

But here are some interesting points on why not to use xhtml http://meiert.com/en/blog/20081219/html-vs-xhtml/

Filip Ekberg
There may be many reasons to choose HTML versus XHTML. The document size, in my opinion, is not anywhere near a top consideration.
Jon Trauntvein
Exactly, i would NEVER ever use HTML when I get a new web-project.
Filip Ekberg
You can write very clean HTML code, which is OK as long as you don't need to treat it like XML (XSLT and such).
PhiLho
A: 

Depending on what your requirements are it depends what you should use. If you were going to be using a lot of javascript i'd use xhtml, for me at least it seems that javascript works better using an xhtml doctype ( especially the dom editing and dhtml things ).

that's just my 2 cents, hopefully others will have something more helpful.

John Boker
I doubt it, JS was working long before XHTML was created... Plus internally, browsers see only a Dom, it doesn't matter whether it is built from HTML or XHTML.
PhiLho
Actually lots of popular Javascript code breaks in XML mode. You might be referring to standards mode vs quirks mode, but it has nothing to do with XHTML (it's side effect of using inappropriate XHTML doctype on HTML page).
porneL
+5  A: 

Some other questions about this topic:

There are quite a few more questions about that (or a similar) topic, e.g. using the following search on SO:

http://stackoverflow.com/search?q=xhtml+html

M4N
It would probably be more useful if your links contained the actual question rather than just a URL.
cletus
Also, this is more of a comment than an answer.
Greg Mattes
Add this one too to the list: http://stackoverflow.com/questions/523706/xhtml-or-html-4-01/2616754#2616754
Marco Demajo
+2  A: 

Pick one and stick to it, and be as compliant as possible in the face of other constraints. Don't think for a second, however, that HTML vs. XHTML is a more important issue than getting the job done and the site up and running, because that's what's going to bring in the revenue. Users don't give a toss about XHTML.

Rob
Yeah my point is that i couldn't care less myself as long as the browser renders it correctly but there might be some hidden cost in not choosing what the browsers deal best with. In other words: will sticking to HTML give me less rendering/css troubles?
L. De Leo
Not necessarily fewer rendering/css troubles either way. If you need the xml nature of XHTML for any reason go with that, otherwise using html is more tolerant of mistakes than XHTML.
Alohci
A: 

If you really don't care about sketchy support, try HTML 5. My fallback would be HTML 4.01 Strict, unless I needed something like inline SVG or similar, in which case it's XHTML (served as XML) all the way.

Hank Gay
+3  A: 

if you go xhtml, please choose xhtml 1.0, and not xhtml 1.1, unless you intend to serve it with a correct xml or xhtml mimetype. Actually, on second thought, don't do that either. There are huge crippling disadvantages to serving xhtml 1.0 or 1.1 with the correct mimetype. The slighest error and you get yellow screen of death!

The w3c specs say that it is okay to serve xhtml 1.0 as text/html as long as you follow certain rules for backward compatibility (mainly in self closing tags, include a space before the / forward slash.

Aside from that there's other arguments for/against. I tend to use xhtml because of the various tools and libraries that are available that can parse valid xml, making thinks like xslt transformations to/from xhtml possible. (useful?).

Another thing is that it's possible to parse valid xml in flash- so you may choose xhtml for dynamic content replacement with a flash movie, or otherwise dynamically load xhtml content into a flash movie. Or really, anything that can read xml can read xhtml. that's a lot of things.

Breton
I transform HTML<>HTML happily using PHP's DOMDocument::loadHTML and XSLT's HTML output mode. It's even more robust, because you don't have to set up XML catalog to parse named entities without hitting W3C servers.
porneL
my point is that some tools, like flash, don't have a full on html parser built in.
Breton
It is intentional that browsers refuse to parse incorrectly formatted xhtml served as XML. If they all did that, then the quality of code on the web would be much better.
Casebash
@Casebash the genie is out of the bottle already. The result of strict parsing isn't better quality code, it's the utter failure of XHTML (proper) to be adopted, as it's impractical and incredibly risky for large organisations to serve code with a high risk of breaking completely, (rather than just breaking partly, like html), not to mention the failure of the market leader, IE to recognize the correct mimetype.
Breton
+2  A: 

My advice is to use HTML4 Strict or HTML5. Valid, in standards mode, with CSS for layout. You'll get all the benefits that are commonly associated with XHTML, but without any of the problems.

Remember: XHTML DOCTYPE does not enable parsing of document as XHTML. It only enables standards mode, the same which is available to HTML 4 Strict and HTML 5.

  • XHTML/1.0 has identical semantics and practically identical CSS support as HTML 4.01.
  • Valid HTML 4.01 is parsed unambiguously just like valid and well-formed XHTML/1.0.
  • XML DOM gives you namespaces support, but takes away support for document.write and innerHTML.

Without proper XML MIME type set in HTTP headers (not document itself) all you get is parsing of everything as HTML and HTML DOM.

XHTML is still not supported in Internet Explorer at all (including IE8). The best you can get in IE (and Googlebot) is XHTML misinterpreted as HTML with syntax errors (whether that's 70% or 30% of your audience, it's still something to think about).

Try forcing "XHTML" websites to use actual XML mode, and you'll quickly notice that almost nobody uses XHTML. They just slap wrong DOCTYPE on their HTML:

These "XHTML" pages work only because they're usually interpreted as HTML.

porneL
+16  A: 

I always use HTML 4.01 strict for the time being. HTML 5 isn't definitive yet. I used to be a diehard XHTML user, but my reasons etched away and I'm much happier and more productive.

The arguments for XHTML generally tend towards the "cleaner markup" or talking about well-formed markup. This seems mostly like a strawman argument, and doesn't hold up under a thorough beating.

If XHTML is guaranteed to be parsed by an XML parser, it generally won't look cleaner than HTML 4.01 strict (just comparing strict doctypes).

For one, having to write URLs as http://example.com/?foo=bar&amp;amp;baz=qux looks awkward. Declaring the entity types gets old.

The other thing is that markup generally doesn't translate remarkably well as an XML Tree, but a Dom tree is fine.

HTML 4.01 strict is moderately easier to use and create valid sites. You don't have to put meaningless closing tags on elements like <img>, <br> or <link>. Just putting the backslash doesn't change anything of any particular meaning.

Douglas Crockford, of Yahoo and everything markupy, says it best to think of the markup as an application delivery format.

As such, what is going to be the easiest to deliver and more robust and reliable. This is what ultimately made the decision for me. All web browsers handle XHTML differently, and require munging of the Content-type header. If you use "text/xhtml" or "text/xml" you get different results.

Additionally, "text/xml" doesn't play nicely with REST because that should mean XML serialization of the data and not a formatted markup page (Safari gets this one wrong, in my opinion, by requesting text/xml before text/html as desired content-types!)

So, use HTML 4.01 because:

  1. It works more similarly across all browsers
  2. Doesn't require Content-type based handling (text/html does the trick across the board)
  3. Isn't as brittle as XHTML
  4. HTML 5 doesn't offer anything significant over HTML 4.01 strict
How is XHTML brittle? The only real difference IMHO is that XHTML can be parsed by XML parsers, which is quite often a large bonus.
singpolyma
@singpolyma: I agree, XHTML isn't brittle, it is *strict*. Which is a good thing IMHO because it forces you to be as accurate as possible about what you want.
Evan Teran
@jshirley: +1 and well said. I would also add: 5. In HTML you can still use the useful and fast JS function document.write cite: http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite. 6. in HTML you don't have to waste time wrapping script that might contain reserved char in CDATA code.
Marco Demajo
A: 

It never mattered.

Paul D. Waite
A: 

In most case, it does not matter. In fact, using XHTML cause more headache. However, there is a few situation that XHTML is needed. I can think of two.

First, if you want to use embeded SVG, you need XHTML.

Second, if you want to use HTML mark up as XML. Sometime (for unknown reason), I found that my AJAX request verify the code even when I mark it to be html or text. And to quickly avoid that, I change it to XHTML.

That is all.

NawaMan