开发者

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

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

What is th开发者_开发问答eir 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?


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!


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜