views:

45

answers:

3

What are benefits to have Doctype DTD as a first element in our (X)HTML file?

What is their role in web development and browser (Desktop and Mobile both) compatibility?

What are cons to not to use any Doctype?

Are all browser does affected from Doctype?

+2  A: 

A webpage is not valid without a doctype, period. The browser will try to render it using whatever default doctype it will use (usually HTML 4.0 Strict is what my browser will use). The doctype is there to tell the browser and the world what kind of page you're giving them so it knows exactly how to handle everything in it. There are no pros and cons, just use a doctype. It's one extra line at the top of the page!

More information from w3schools!

animuson
There are pros: It gives the web actual standards, and makes our lives easier. Imagine if every browser was like IE, making up their own unique html, css and javascript junk. Headache.
digitalFresh
so page will not valid this is the only cons.
metal-gear-solid
no answer and more info on this page http://www.w3schools.com/tags/tag_doctype.asp My question is not What is doctype and How to use?
metal-gear-solid
@digitalFresh: Fair point. I was just trying to point out that you shouldn't bother thinking of pros and cons, you just use a doctype always.
animuson
and many browsers might have problems rendering your page. If you want your site to be enjoyed by many people, please use a doctype.
digitalFresh
@metal-gear-solid: The website merely reinforces what I said. Any website you visit about doctypes will say the same thing. No website even discusses the possibility of not having a doctype.
animuson
@animuson - you are right but we should try to know about the reasoning and pros and cons of whatever we are using.
metal-gear-solid
Here: http://www.w3.org/QA/Tips/Doctype#id02
digitalFresh
@animuson "No website even discusses the possibility of not having a doctype" Thats why i asked this question on SO.
metal-gear-solid
@digitalfresh - + 1 good link. so there are 2 pros. 1) it helps to Markup validators 2) it triggers "standard" rendering mode"
metal-gear-solid
I don't understand the use of pros and cons, they're just opposites of each other in this case. Pro: It makes the page compatible with the validator. Con: It makes the page incompatible with the validator. What do we achieve from that?
animuson
"Con: It makes the page incompatible with the validator" but not with browser.
metal-gear-solid
@metal-gear-solid: We weren't talking about the browser, we were talking about the validator. It's the same with the browser. Pro: It triggers a standard rendering mode. Con: It makes the browser guess on everything (non-standard). The validator merely helps you make your page valid so the browser will know what to do with everything and not have to guess.
animuson
A: 

It specifies to the rendering engine what parsing style it should use. Default is loose HTML, but you can specify strict adherence to different HTML specs. Considering the tolerance most engines have for badly written HTML they are not not strictly necessary, but they are handy for forcing the browser to use the parsing style that you want your website to be rendered in.

For example to force IE to use quirks mode to render your site, or force it to use standards mode.

Take a look here for more info: http://en.wikipedia.org/wiki/Document_Type_Declaration

download
"but they are handy for forcing the browser to use the parsing style that you want your website to be rendered in" but how?
metal-gear-solid
@metal-gear-solid: the browser sees the doctype declaration and uses the corresponding rendering engine. IT doesnt "force" anything.
digitalFresh
it means all browsers are having both type of rendering mode but by default all browser always render quirkmode. am i right?
metal-gear-solid
aka by default, all browsers render in "insane errors are ok" mode.
digitalFresh
+2  A: 

To quote the HTML specification:

DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the relevant specifications.

Ms2ger