开发者

Actual Use of Doctype

While I have gone through a lot of information on w3.org about Doctype and understand the different types of doctypes (Transitional, Strict, Frameset)

I am still not clear what is the actual use of using Doctype on pages?

I mean:

  • Is it to prevent developers from using certain tags in the code (e.g. By using strict, we restrict the developer from using certain deprecated tags like font, center, etc)

  • Is it to give some information to the browser and if yes, does it impact

    rendering in any way?

Please help me w开发者_如何转开发ith the same. Thank you.


It's to tell the browser how it should interpret the code in the page.

(If you use it as a tool to control developers, you have a management problem...)

The doctype does impact the rendering, what tags are valid, which attributes they can have, and also how you can use them in client script. A transitional doctype is more forgiving than a strict, but the HTML version also affects what's valid.

The biggest difference is between having a doctype tag and not having one, especially in Internet Explorer. Without a doctype tag it will render the page in quirks mode, which among other things include use of the non-standard box model, which can mess up your layout completely.


The Doctype will influence how a browser will parse your code. Since most browsers are pretty lenient when it comes to parsing HTML, the changes are not as massive as one might expect.

Note that HTML5 has a pretty well-defined parsing algorithm that even defines how ill-formed HTML is to be interpreted. On HTML5-enabled browsers this algorithm is used when the HTML5 doctype is present.


  1. Yes, if you use strict and then use deprecated tags, the page will not validate when you run it through the W3C validator

  2. Yes, it will impact rendering.

Without DocType, the browser will render you page using quirks mode, which is to say that certain tags will render differently on browsers. Some of these tags are now deprecated and some others have been standardized.

DocType (transitional & strict) are used to tell the browser that you are following the HTML standards and to render the markup as per the standard W3C spec.


The doctype does impact the rendering, what tags are valid, which attributes they can have, and also how you can use them in client script. A transitional doctype is more forgiving than a strict, but the HTML version also affects what's valid.

The biggest difference is between having a doctype tag and not having one, especially in Internet Explorer. Without a doctype tag it will render the page in quirks mode, which among other things include use of the non-standard box model, which can mess up your layout completely.

You can visit http://www.teachw3.com/html_tutorial/html_home.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜