Exitos
Exitos

Reputation: 29750

What is the point in the doctype declaration at the top of html form? Does it change anything?

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

Answers (4)

bgporter
bgporter

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

Quentin
Quentin

Reputation: 944555

In HTML 2.0, 3.2, 4.x and XHTML 1.x:

In theory:

  • It allows the user agent to decode entities (e.g. &hellip; to …)
  • It allows a validator to determine which tags, attributes and attribute values are allowed where

In practice:

  • It allows a validator to determine which tags, attributes and attribute values are allowed where
  • It allows browsers to make a guess as to if the author has a clue about what they are doing and switch between standards mode and quirks mode

In HTML 5:

  • It is a mystic string used to start a document so that standards mode is triggered

Upvotes: 0

Yoshiyahu
Yoshiyahu

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

meder omuraliev
meder omuraliev

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

Related Questions