54

It seems that HTML 5 is going to be supported (partially) by Firefox 3.1 and other browsers. It is adding support for video and audio as tags, but these are new tags that XHTML 1.0 Transitional does not recognize. What is the behavior supposed to be if I use a new HTML 5 tag in a future version of Firefox but use the DTD for XHTML? And what if I mix HTML 5 markup with XHTML 1.0 Trans?

This is getting confusing. Why didn't they just add these tags to XHTML? How do we support both XHTML and HTML 5?

Video on HTML 5: http://www.youtube.com/watch?v=xIxDJof7xxQ

Brennan
  • 11,546
  • 16
  • 64
  • 86

9 Answers9

97

HTML5 is so much easier to write than XHTML 1.0.

  1. You don't have to manually declare the "http://www.w3.org/1999/xhtml" namespace.

  2. You don't have to add type attributes to script and style elements (they default to text/javascript and text/css).

  3. You don't have to use a long doctype where the browser just ignores most of it. You must use <!DOCTYPE html>, which is easy to remember.

  4. You don't have a choice to include or not include a dtd uri in the doctype and you don't have a choice between transitional and strict. You just have a strict doctype that invokes full standards mode. That way, you don't have to worry about accidentally being in Almost standards mode or Quirks mode.

  5. The charset declaration is much simpler. It's just <meta charset="utf-8">.

  6. If you find it confusing to write void elements as <name>, you can use <name/>, if you want.

  7. HTML5 has a really good validator at http://validator.nu/. The validator isn't bound by a crappy DTD that can't express all the rules.

  8. You don't have to add //<![CDATA etc. in inline scripts or stylesheets (in certain situations) to validate.

  9. You can use embed if needed.

Just syntax-wise, when you use HTML5, you end up with cleaner, easier to read markup that always invokes standards mode. When you use XHTML 1.0 (served as text/html), you're specifying a bunch of crud (in order to validate against a crappy dtd) that the browser will do automatically.

Shadow2531
  • 11,980
  • 5
  • 35
  • 48
  • 4
    Great answer. You listed exactly what I cared about. –  Feb 27 '09 at 18:38
  • +1 I'm thinking to use HTML5 after reading your answer but what about IE? – Jitendra Vyas Aug 23 '10 at 08:36
  • and here are some cons http://stackoverflow.com/questions/1298610/what-are-the-pros-and-cons-of-adopting-html-5-now-for-a-site-redesign/1298624#1298624 main thing is what will happen on IE if javascript is disabled. – Jitendra Vyas Aug 23 '10 at 08:54
28

Myths and misconceptions abound in this thread.

  1. XHTML 1.0 is older than HTML 5. It cannot use any new vocabulary. Indeed, its main selling point was that it uses exactly the same vocabulary as HTML 4.01.

  2. There will be no XHTML 1.2 - most probably. And it is not needed. XHTML 5 is the XML serialization of HTML 5. Identical vocabulary, different parsing rules.

  3. HTML has never been treated as true SGML in browsers. No browser has ever implemented an SGML-compliant parser. HTML 5 will make this fact into a rule and the HTML serialization will follow todays de facto standard. One could perhaps say that it is "SGML-ish".

  4. As it has been stated, the DTD serves exactly one purpose IN BROWSERS, and that is to distinguish between standards compliance mode and quirks mode. Thus it affects only styling and scripting. If you are using frames on a page with astrict doctype, they will render just fine. As will <embed> and even <marquee> - even though the latter is an abomination and the former not in any current standard. It is part of HTML 5, though.

  5. Video and audio can be used regardless of serialization, XML or HTML. they are part of both HTML 5 and XHTML 5. Once the parsing stage is over a browser will have constructed an internal DOM of the document. That DOM will be for all practical purposes the same regardless of serialization. And yes, XHTML sent with text/html is still normal html, regardless of doctype.

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
10

Well, generally speaking HTML is SGML and XHTML is expressed in XML. Because of that, creating XHTML is connected with more restrictions (in the form of markup) than HTML is. (SGML-based versus XML-based HTML)

As mentioned on Wikipedia, HTML 5 will also have a XHTML variant (XHTML 5).

Rule of thumb: You should always use valid markup. That also means that you should not use the mentioned <video> or <audio> tags in XHTML 1.0 Transitional, as those are not an element of that specification. If you really need to use those tags (which I highly doubt), then you should make sure that you use the HTML 5/XHTML 5 DTD in order to specify that your document is in that DOCTYPE.

Using HTML 5 or XHTML 5 in the given state of the implementation (AFAIK, the standard is not even settled, yet, correct?) could be counter-productive, as almost all users may not see the website rendered correclty anyways.

Edit 2013: Because of the recent downvotes and since this accepted answer cannot be deleted (by me), I would like to add that the support and standardization process of HTML5 is nowadays totally different to what it was when I wrote this answer five years ago. Since most major browsers support most parts of the HTML5 draft and because a lot of stuff can be fixed with polyfills in older browsers, I mainly use HTML5 now.

hangy
  • 10,765
  • 6
  • 43
  • 63
  • 9
    Voted down because the answer talks about SGML and HTML 5/XHTML 5 DTD even though (as pointed out in other answers) HTML5 is not SGML-based and does not have a DTD. – hsivonen Nov 02 '08 at 20:56
  • Voted down because he doesn't provide a detailed enough explanation to be particularly helpful. – Jay Taylor Mar 10 '11 at 21:16
  • 2
    @pyrony: Just wondering ... are you voting this answer down because it is the accepted answer and does not provide you all the information you want or because it is wrong/incomplete? In the latter case you may want to vote down a lot of other answers, too. :) I'd just like to avoid getting negative reputation for this 1.5y old answer - and putting it to modern context does not really fit, because the state of XHTML and HTML5 has probably changed quite a bit since the original question/answer. – hangy Mar 11 '11 at 06:39
  • I don't think it really answered the question. I don't like voting things down and do it only rarely...have gone ahead and upvoted some of your other answers to compensate :p sorry matey – Jay Taylor Mar 14 '11 at 19:05
  • 1
    @pyrony Haha no problem and thanks for votes and explanation. :) I was just wondering if the answer might be voted *just* because it is (for some reason) the accepted answer. – hangy Mar 14 '11 at 20:49
7

You might be looking at the problem the wrong way because the relationship to XHTML 1.x section, HTML 5 states:

"This specification is intended to replace XHTML 1.0 as the normative definition of the XML serialization of the HTML vocabulary."

Now that language is controversial (the XHTML 2 WG has disputed it and the HTML WG is trying to resolve the differences...) but that's where we stand right now.

A couple of notes:

soypunk
  • 291
  • 1
  • 2
  • Sorry, there are a number of real problems here. First, it's extremely unlikely that the W3C will actually deliver an XHTML 5 DTD given they're not going to create an HTML 5 DTD and the "specification" is actually a description of browser behaviour, not a syntax spec. – Ichiro Furusato Dec 13 '12 at 10:10
  • Second, *all* of the HTML specifications (as delivered by the IETF, ISO, and W3C) have always been defined as SGML markup languages, with SGML DTDs and SGML declarations. Valid HTML 2.0, 3.2, and 4.0 document instances can all be parsed as SGML using James Clark's SP. – Ichiro Furusato Dec 13 '12 at 10:18
4

Keep in mind that doctypes only serve one purpose in browsers: switch between quirks, almost standards and standards mode. Therefore, using <video> and <audio> will work with any doctype declaration. IMO, using an XHTML doctype is quite useless, as every page you send with text/html MIME type is parsed as (tag-soup) HTML anyways. I suggest using the HTML5 doctype (<!doctype html>), as it is easier to remember and doesn't force you in XML syntax without a reason.

Why didn't they just add these tags to XHTML?

They actually did, there is an XML serialization of HTML 5 (XHTML5). To use this, you have to send your pages with an XML MIME type, such as application/xhtml+xml. This is not (yet) supported by IE, though.

Ms2ger
  • 15,596
  • 6
  • 36
  • 35
3

What is the behavior supposed to be if I use a new HTML 5 tag in a future version of Firefox but use the DTD for XHTML?

And what if I mix HTML 5 markup with XHTML 1.0 Trans?

If your markup isn't implemented as part of your chosen DTD - then logically, that markup shouldn't be followed. But browser implementations aren't always strictly logical.

Why didn't they just add these tags to XHTML? How do we support both XHTML and HTML 5?

xHTML is not better than HTML, but it's more suited to some applications. One of the main benefits of xHTML is that it can be transformed into different formats using XSLT. For example, you could use XSLT to automatically transform xHTML into an RSS feed or another XML format.

You don't need to support both formats - weigh up the benefits/drawbacks for each with your project's requirements. HTML 5 probably won't be standard for quite some time.

codeinthehole
  • 8,876
  • 3
  • 25
  • 34
1

(X)HTML5 is just the next version. You should be using XHTML1.1 until XHTML5 is well-supported.

You probably should not use the backwards-compatability SGML profile of HTML5. It makes things harder for scrapers and small parsers.

singpolyma
  • 10,999
  • 5
  • 47
  • 71
  • 2
    XHTML 1.1 is not even supported by IE8. It is unfortunate, but a reality for now. Why would I want to use that at all for a widely used web site? – Brennan Oct 21 '09 at 03:44
  • XHTML1.1 is just XHTML1.0 with some more deprecations and stricter doctype. IE treats it as tag soup instead of knowing the doctype, but since IE is pretty quirky anyway I've never had a big problem with that. – singpolyma Oct 22 '09 at 14:04
-2

Your doctype will tell the browser whether you're using HTML5 or XHTML. You can't just shove a tag from one doctype into a document of another doctype and expect it to work. Without a doctype, it's all just tag soup anyway.

Greg
  • 316,276
  • 54
  • 369
  • 333
  • Why was this voted down? Is this an inaccurate statement? Seems to jive with answers from others... – Adam Oct 12 '10 at 15:59
  • @Adam: Because few if any browsers pay attention to the actual doctype. In practice, you *can* just shove a tag from an HTML doctype into XHTML, and it will usually just work -- in many cases, browsers just apply a given doctype regardless. The doctype line's biggest real function in almost any browser is to inform the browser that the page makes an attempt to conform to *some* (X)HTML standard, so the browser should attempt to render the page in "standards mode", which slightly changes the box model among other things. – cHao Nov 05 '10 at 10:12
  • 2
    Internet Explorer 9 at least requires that you specify the doctype as in order to use new HTML5 features of the DOM and the JS engine. – Adam Nov 10 '10 at 18:59
-2

Don't use things like video/audio tags when 99% of people won't be able to view it properly on their browser. For either of these two examples I'd suggest using FLV.

As far as why they don't add it to XHTML... firstly 1.0 isn't the most recent version, 1.1 was released a while ago.

Eventually things get standardized and we'll see these types of tags in both standards, but for now just do what you can to ensure the most amount of people can view your content.

Andrew G. Johnson
  • 26,603
  • 30
  • 91
  • 135
  • 4
    In fact, the video tag has the same backwards-compatibility the iframe tag has - if the browser doesn't support it, it will show its inner content unformatted. So you could enclose your flash embed code within the videotag and it will still be compatible with all browsers. – Jonathan Prior May 20 '09 at 17:41
  • 2
    "Video for Everybody" explains how to use (X)HTML5 video with a flash fallback and then a download fallback (some people don't have flash). See also "Dive into HTML5". Also, Flash can play MP4 H.264 video, so you don't need FLV. – TRiG Jun 25 '10 at 11:15
  • Oh, hey, this got obsolete fast. – Ry- Aug 10 '13 at 03:59
  • @minitech - True then, true now. – Andrew G. Johnson Aug 10 '13 at 04:54
  • Well, actually, none of it is true. 1) I don’t have Flash installed and it doesn’t work on iOS. 2) It hasn’t been added to XHTML. 3) Even then, fallback content was possible. – Ry- Aug 10 '13 at 14:22
  • @minitech - Sorry didn't realize you don't have Flash installed, my entire point is invalid. Please let me know if you decide to install it so I can rethink my entire life. – Andrew G. Johnson Aug 12 '13 at 11:18
  • @AndrewG.Johnson: I… wow. Do you have a mobile device from Apple? Do you know anybody who does? – Ry- Aug 12 '13 at 14:44
  • @minitech - Yes. Yes. – Andrew G. Johnson Aug 12 '13 at 14:52
  • @AndrewG.Johnson: Are you aware that Flash does not work on them? – Ry- Aug 12 '13 at 14:53
  • @AndrewG.Johnson: Are you aware that Flash is disabled by default on Modern UI IE 10? – Ry- Aug 12 '13 at 14:55
  • Yes? No? Doesn’t matter, I get the feeling that’s not going to change your mind. Are you aware that your 99% figure is not “true now”? Did “true now” include “do what you can to ensure the most amount of people can view your content” and nothing more? [It’s closer to 15% today.](http://caniuse.com/#feat=video) – Ry- Aug 12 '13 at 15:05
  • Fallback Flash is great. Only Flash is an instant recipe for annoying a large group of people. Your answer is obsolete and your stubbornness is astounding. – Ry- Aug 12 '13 at 15:07
  • @minitech Great let me know if there's any other life changes you feel I should be making and I'll try to integrate them ASAP – Andrew G. Johnson Aug 13 '13 at 13:08
  • Why are you making this such a big issue? Fix your answer or delete it. Sheesh. – Ry- Aug 13 '13 at 14:42