tags:

views:

1011

answers:

7
+40  Q: 

What's up, Doctype?

  • What is doctype and why do I want to use it?
  • What are the different doctypes I can use?
  • What is the difference between standards and quirks mode, what are some quirks I may run into with differently set doctypes?

Lastly, what is the proper doctype that I should be using?

+3  A: 

A doctype defines which version of HTML/XHTML your document uses. You would want to use a doctype so that when you run your code through validators, the validators know which version of HTML/XHTML to check against. This page provides a good overview:

Don't forget to add a doctype

Common doctypes you can use are listed here:

Recommended list of DTDs

Which doctype you should go with depends on the code you're using, but to get an idea, try running your code through the W3C validator and use the Document Type drop-down menu in the "More Options" menu to try different doctypes out.

W3C Markup Validation Service

single link posts with no explanation? you can do better.
Jeff Atwood
Sorry, I thought the link provided a better answer than I could write. But you're right, I still should have added an explanation. It's been added now. :)
A: 

A doctype is a document that describes how the contents of a xhtml-like document can look like (like a webpage). Note: this defines only the syntax of said page, the rendering of the page is NOT defined by the DTD!

For example, a doctype could define how the <table>-tag can look like - which attributes it accepts, and which values/valuetypes are accepted for each attribute. Think of it as a lexicon for your current webpage.

Wikipedia has an informative page on the various Doctypes that are in common use. Mind you - there's nothing stopping you from creating your own doctype. The chances are, however, that the browser probably doesn't know how to render your document.

Which DTD to use depends on what you are going to write. XHTML has a whole different DTD than HTML, for example.

Henrik Paul
+2  A: 

First of all there is no one doctype you should be using, but most designers try to make it work within XHTML 1.0 Strict.

A doctype is nothing more than a declaration of what tags you can use within your html (though the browsers can use more or less than what is defined) You can actually open up the doctype file and start reading (XHTML 1.0 Strict)

If you do not specify a doctype, the browser will try its best to guess but not always hits the correct type.

Quirks mode is just a technique used by browsers to be backwards compatible, a great example of quirks mode is how IE renders boxes

Ólafur Waage
+1  A: 

Doctypes tell the browser in what language the page is written in, be it html or xhtml. For example

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"&gt;

tell the browser to render the page as HTML4 strict. Older browsers used to render pages not correctly and therefore newer browsers use to simulate errors of the older browsers when they find an old doctype.

Today you should use at least HTML4 or better XHTML.

Here's a blog entry about doctypes from a list apart: http://www.alistapart.com/stories/doctype/

Georg
+4  A: 

The DOCTYPE tells the consuming user agent (web browsers, web crawlers, validation tools) what type of document the file is. Using it ensures that the consumer correctly parses the HTML as you intended it.

There are several different DOCTYPES for HTML, XHTML, and Framesets and each of these has two modes Strict and Transitional. Strict says that your markup is using the defined standards exactly. See W3C DTDs page for further details.

Quirksmode is basically the the layout method from the browser wars days when the standards were much less respected and defined. Generally a standards mode page, that is valid, will layout more consistently across various browsers, but may lack certain features that you require. One such features is the anchor tag's target attribute. The Quirksmode site is a great resource for these differences.

One final thought is that the new HTML5 standard proposes using a very simple DOCTYPE:

<!DOCTYPE html>

Using this DOCTYPE is a forward compatible way to specify that your pages are in standards mode, and are HTML. This is the method that Google uses, and is reasonably easy to remember. I recommend using this DOCTYPE unless you plan to use XHTML.

Rob
+14  A: 

Basically, the DOCTYPE describes the HTML that will be used in your page.

Browsers also use the DOCTYPE to determine how to render a page. Not including a DOCTYPE or including an incorrect DOCTYPE can trigger quirks mode. The kicker here is that quirks mode in Internet Explorer is quite different from quirks mode in Firefox (and other browsers), meaning that you'll have a much harder job trying to ensure your page works consistently in all browsers if pages are rendered in quirks mode than you will if they are rendered in standards mode.

Wikipedia has a more indepth summary of the differences in rendering when using various DOCTYPEs. Note that there are some subtle differences between the "skinny DOCTYPE" (<!DOCTYPE html>) and other DOCTYPEs that trigger "standards compliant" rendering.

There is quite a bit of debate about the use of XHTML which is covered well in XHTML — myths and reality.

Personally I favour the HTML 4.01 Transitional DOCTYPE:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
wrumsby
A: 

On the web, a doctype does nothing but tell the brower if you want standards, almost standards, or quirks mode.

What changes in quirks mode depends on the browser: Firefox, Opera, Safari, and Chrome implement a limited set of quirks, like removing the space for text descenders in code like <table><tr><td><img></td></tr></table> (solution: td img { vertical-align:bottom; }). IE, on the other hand, reverts to the rendering engine in IE5.5. That means that you won't be able to use any of the new features implemented since 2000.

To trigger standards mode, I suggest using the HTML5 doctype, <doctype html>, as it is the easiest to remember.

Ms2ger