It's raining doctypes and validations
Why you should care about the doctype of your document
What's a doctype?
A valid HTML document declares what version of HTML is used in the document. The document type declaration names the document type definition (DTD) in use for the document
as quoted from the w3c documentation.
So, as per definition, the doctype declares the version of html that you've used in your document. Why, ain't that nice?
Why should I care?
Back-end developers won't care much, except for those few occasions were they might be inclined to stumble through the pages using an xml-parser. Front-end developers however should care verry much.
A page will behave differently based on the doctype you set at the start of the page. When no doctype, or an old version is present, the browser will render the page in 'quirks' mode. When a valid doctype, html 4 or later, is present the page will be rendered in standards-compliant mode. It doesn't really matter wether your html is valid, that's a different story.
'Quirks' mode means that the browser will behave according to the 'old' ways of rendering, referring back to the time Netscape 4 and Internet Explorer 3 were fighting their last battle. Anybody who was around on the web at the time has heard of, or experienced the differences in the browsers causing pages to behave erratically from one browser to the next.
In 'standards' mode the browsers try to adhere to the specifications with more accuracy, resulting in far less differences. Choosing to supply a valid doctype is your way of telling the browser you know what you're doing. Essentially this was the intend of the behaviour, a way of differentiating existing 'quirky' websites from those build by more modern standards and techniques.
I will get into validation in a little more detail some day, for now I would like to add what doctypes mean towards validation. A doctype will allow you to validate your html. Since it describes the version of your html a validator will know what specification to use when reading your document.
However, the rendering mode is not influenced by the validity of the source-code. That is not to say invalid code can't wreck the way your page renders, but like I said, more on that some other day...
Cool! I wanna know more
Well, it's been around, so a google search on doctype switching will show you many, many links, I just wanted to make you aware of it's existence, check out some of my prefered links for the details:- Eric Meyer on CSS, bonus material, my personal north-star on webstandards. Read Eric's books on css if you want an introduction based on real-life samples!
- Mozilla's doctype switching docs
- Opera on doctypes
- Microsoft MSDN
- Eric Meyer on O'Reilly's knowledgebase