views:

483

answers:

7

What is your preferred format for html content?

Why do you choose one over the other?

+3  A: 

I use XHTML 1.0 Strict, just because I immediately get notified on any coding errors. Additionally, I can use XML namespaces for SVG or other stuff, although I'm currently converting SVG images to png before displaying them.

Although using the XML prologue puts IE6 into Quirks mode, I'm lucky insofar as that my web clients are standard-compatible. For my personal (publicly available) pages, I'm using XHTML with prologue and doctype. If you are using a broken browser, my page may not be rendered correctly. So what? (Plus, most of it is plain text anyway atm). The only concession is Content-Type text/html for older browsers and not totally breaking old IEs. But if you application/xhtml+xml is in your Accept header, you may get it.

phihag
I'd drop the prolog. If you're using the default encoding UTF-8 (which generally you should be), it doesn't gain you anything, just more header cruft. Getting Standards Mode in IE by removing it is a bonus.
bobince
+2  A: 

If you want to support IE, you're stuck with HTML4.01 or html-compatible XHTML1.0, preferably in the strict variant. If not, choose whichever dialect you like best.

I myself mostly stick with HTML because XHTML is only needed when inlining data from other XML-dialects or when customizing doctypes, both of which will break compatibility with HTML and tagsoup-parsers.

In my opinion the only valid reason for choosing html-compatible XHTML1.0 over HTML4.01 is tool support: E.g. XHTML allows for better validators because of stricter syntax requirements and can be auto-generated via XSLT.

Christoph
The syntax is stricter, but they've had to make the structure looser. So XHTML validation can't pick up `<a><b><a>…</a></b></a>` as an error and they've had to make `<tbody>` an optional element instead of one that is implied if you don't specify it (or thead/tfoot) explicitly.
David Dorward
Oh, and you can generate HTML with XSLT too.
David Dorward
+10  A: 

HTML-compatible (Appendix C) XHTML 1.0 Strict, served as text/html.

No, it doesn't get you anything on the browser in comparison to HTML 4.01. But I'm not doing it for the browser. It lets me manage my production systems at the server-side using plain XML tools, and anyone who needs to scrape my pages can do it with an XML parser instead of having to worry about the difficulties of parsing likely-malformed HTML.

The rules of XML may be stricter than HTML, but they're also simpler. Apart from the / in empty element syntax, XHTML is basically the same thing you'd be writing if you were doing HTML4 properly. You always quote your attributes like this, you always open and close your elements consistently, and so on.

bobince
+5  A: 

XHTML is not very different from the HTML 4.01 standard.

The Most Important Differences:

  • XHTML elements must be properly nested
  • XHTML elements must always be closed
  • XHTML elements must be in lowercase
  • XHTML documents must have one root element
  • XHTML Attribute names must be in lower case
  • XHTML Attribute values must be quoted
  • XHTML Attribute minimization is forbidden
  • XHTML The id attribute replaces the name attribute
  • XHTML DTD defines mandatory elements

HTML does not force these things but most browsers are quickly starting to expect it. Despite IE8 dropping it's Trident engine it looks as though they will still not support XHtml SO Strict is probably going to be your best option.

UPDATE:

Web Standard committee have opted against XHTML 2 and for HTML 5.

cgreeno
‘documents must have one root element’ and ‘id attribute replaces the name attribute’ were already true in HTML 4.01, so they're even less different than that :-)
bobince
HTML elements must be properly nested too, and HTML elements must always be closed (but this might happen implicitly). Unsurprisingly, the HTML DTD also defines mandatory elements.
David Dorward
+9  A: 

I use HTML (4.01 Strict or 5). This article explains the reasons why very well: http://www.webdevout.net/articles/beware-of-xhtml

Basically, with the state of browsers at the moment, XHTML as true XHTML isn't relaistic, and XHTML served as HTML gets treated as HTML, so you may as well use that.

Also, you don't have to use HTML 4.01, the HTML 5 doctype is now a viable option:

What's nice about this new DOCTYPE, especially, is that all current browsers (IE, FF, Opera, Safari) will look at it and switch the content into standards mode - even though they don't implement HTML5. This means that you could start writing your web pages using HTML5 today and have them last for a very, very, long time.

http://ejohn.org/blog/html5-doctype/

Jack Sleight
A: 

I use XHTML 1.0 STRICT for better cross-browser compatibility. (i.e. less IE/browser-specific hacks to use).

Nimbuz
http://www.w3.org/TR/xhtml1/#guidelines is quite a lot of hacks which are almost entirely for the benefit of IE these days! :)
David Dorward
A: 

We keep our ... stick to: HTML 4.01 (and in future maybe HTML 5) because:

  1. In XHTML you can't not use the useful and fast* JS function document.write cite: http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite

  2. We would get sick and tired to waste our time adding useless CDATA in code everytime we want to add inline scripts or styles containing reserved chars.

We get things done faster, we don't get frustrated, and our customers are still happy. But this is our personal opinion.

*still faster compared to waiting for document.onload event (or other ways to detect whne page is loaded, i.e. jQuery way).

Marco Demajo
1. Not that useful. 2. You don't have to (unless the data includes reserved characters) and you should be avoiding inline script and style anyway. I'd still use HTML 4.01, but not for those reasons.
David Dorward
@David Dorward: I fixed the answer, I'm interested now in reading your reasons to still use HTML 4.01, could you plz post a brief answer or follow up to this comment?! Thanks!
Marco Demajo