Search code examples
javascriptcsshtmldoctype

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 with the same. Thank you.


Solution

  • 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.