HTML vs XHTML does it still matter? [closed]

2019-01-16 20:21发布

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?

标签: html xhtml
7条回答
我想做一个坏孩纸
2楼-- · 2019-01-16 20:29

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&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
查看更多
等我变得足够好
3楼-- · 2019-01-16 20:30

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.

查看更多
▲ chillily
4楼-- · 2019-01-16 20:32

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.

查看更多
戒情不戒烟
5楼-- · 2019-01-16 20:33

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.

查看更多
在下西门庆
6楼-- · 2019-01-16 20:35

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/

查看更多
我只想做你的唯一
7楼-- · 2019-01-16 20:39

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.

查看更多
登录 后发表回答