views:

511

answers:

3

I recently been learning about DocTypes and was wondering what the differnces between <!DOCTYPE html> and some of the others were.

I know <!DOCTYPE html> is the HTML 5 doctype and it is experimental but was wondering what would happen if I used it instead of the other DocTypes.

Thanks in advance!!!!

+5  A: 

Basically what will happen is that you'll get your page rendered in a "standards mode".

The only reason why you probably shouldn't use the new DOCTYPE is if you want to use XHTML 1.0 markup and conform to XHTML 1.0.

The downside to using HTML5 now is that the spec can change. This makes it important for you to keep up with the spec as it actively changes.

With that being said, I've already started using the new syntax in my pages. Also it guarantees that your page will last for a very, very, long time.

So go ahead, use it (and learn to love how simple it is).

Lucas McCoy
+4  A: 

Lucas nailed the most important aspect. Let me explain this in a slightly different way:

In the browser the doctype serves exactly one purpose, to set the rendering mode: Quirks, almost standards and full standards mode. This used to be simple until MSIE 8 introduced a second switch, "compatibility mode" = MSIE7 bugs and limitations are preserved on purpose.

An HTML5 doctype will (usually) override that setting, and is thus somewhat more powerful than XHTML 1.x or HTML 4.01 doctypes. (MSIE may override it sometimes, though.)

The definitive guide to doctype switching and layout mode is at: http://hsivonen.iki.fi/doctype/

The second thing that will happen is that you get your pages validated according to the HTML5 rules. Some elements and attributes that were allowed in HTML 4 are gone and a bunch of new ones have come. A few syntactic rules have come as well. E.g. this is illegal in HTML5:

<div>
    <p>foo</p>
    <span>bar</span>
</div>

Rule: You must not mix block and inline elements as siblings in HTML5.

The semantics and syntax for HTML5 is mostly like the one in HTML 4, so most well written HTML 4 sites will continue to validate. The main difference is that you mat start to use the new stuff and still be valid.

itpastorn
@Lars - welcome. No need to encode your code that way - start the like with 4 spaces, or click on the Code button (1010101).
Kobi
@Kobi: I fixed it for him.
Lucas McCoy
A: 

The HTML5 doctype isn’t experimental. Ian Hickson tested a bunch of browsers, and found that <!DOCTYPE html> worked the same in them as the HTML 4 and XHTML 1 doctypes.

However, if you use it, then validators will (by default) validate your page as it it’s HTML5, which may not be what you want if you’re actually writing HTML 4 (I think some elements are getting dropped in HTML5, for example. Using them would show up as an error if you validated your page as HTML5.)

Paul D. Waite