Possible Duplicate:
What's up, Doctype?
Adding DOCTYPE is a best practice -- HTML validators expect to see it. In theory, it makes the document better by declaring which flavor of HTML is being used. In other words, it is something you should always do.
That said, I don't see any cases where browsers seem to use it. I've tried multiple flavors of HTML in various browsers and am unable to find a single example where the document renders differently when DOCTYPE is added.
Does anyone know of a case where the DOCTYPE has any real effect in a browser?
This question is different from What is DOCTYPE? which does not ask for specific examples where the presence of DOCTYPE has an observable effect in a browser.
The tag itself has a big effect, mainly for Internet Explorer, as it makes it render the page in a way closer to the norm (if the document doesn't start with the doctype declaration, IE enters quirks mode).
There are many cases when simply setting the doctype fix bad rendering in IE8 or IE9.
This being said, the precise doctype should now not be specified and, as you probably follow the HTML5 norm, you should simply set
<!DOCTYPE html>
(see http://webdesign.about.com/cs/doctype/a/aaquirksmode.htm)
An additional tip :
IE doesn't really follow HTML5 norm as much as it could, except when you insist with a complementary meta header :
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
(see IE9 Float with Overflow:Hidden and Table Width 100% Not Displaying Properly)
Yes, it does have a real effect: it changes the rendering mode of the browser. Most browsers have two rendering modes: standards mode and quirks mode. Some browsers have a third rendering mode usually called "almost standard".
strict
DOCTYPE makes the browser go into standards modetransitional
DOCTYPEWhen in quirks mode, browsers mimic old versions of themselves and render boxes, alignments, etc differently. "Almost standards" mode is standards mode with a different behavior for images in tables to mimic what we used to do in old HTML to align stuff in tables using transparent images.
You can read more about this in this Mozilla Developer Network article: https://developer.mozilla.org/en-US/docs/Quirks_Mode_and_Standards_Mode?redirectlocale=en-US&redirectslug=Mozilla%27s_Quirks_Mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With