Reputation: 29750
Been writing web apps for years and this line:
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Has always confused me. What is it for exactly? What are the implications if I remove it?
I understand the w3c conventions about nested elements etc but what actually happens why is the declaration there do browsers fail or something if I take it out?
Cheers, Pete
Upvotes: 3
Views: 208
Reputation: 36574
The doctype declaration tells the browser how it should interpret the HTML contents that follow. There's a good overview of how and why in the introduction to Mark Pilgrim's book Dive Into HTML 5
Upvotes: 0
Reputation: 944555
In HTML 2.0, 3.2, 4.x and XHTML 1.x:
In theory:
…
to …)In practice:
In HTML 5:
Upvotes: 0
Reputation: 2168
It iforms the browser of what elements will be used, and affects the rendering of the page. (Mostly IE)
In many cases, elements will not always display correctly if a DOCTYPE is left out.
Upvotes: 0
Reputation: 186762
It kicks the browser into standards mode, which makes the browser properly render elements. Not every doctype kicks the browser into standards mode, see this chart. If a valid doctype is not used to kick the browser into standards mode, the browser will basically try to render your page according to "standards" ( or lack thereof ) in 2002-2003 when everyone used crappy table layouts. You do not want quirks mode.
Conclusion: always use a doctype.
Upvotes: 4