Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 895
copenndthagen Avatar asked May 03 '11 06:05

copenndthagen


People also ask

Is it necessary to use DOCTYPE in HTML?

All HTML need to have a DOCTYPE declared. The DOCTYPE is not actually an element or HTML tag. It lets the browser know how the document should be interpreted, by indicating what version or standard of HTML (or other markup language) is being used.

Is writing DOCTYPE necessary?

All browsers need the doctype. Without the DOCTYPE you are forcing the browsers to render in Quirks Mode. The DOCTYPE declaration is <! DOCTYPE html> and is case-insensitive in the HTML syntax.

Why <! DOCTYPE is used in HTML5?

The Doctype is not an element or tag, it lets the browser know about the version of or standard of HTML or any other markup language that is being used in the document. Syntax: In HTML5 the syntax to declare doctype is very simple but in older versions like HTML4.


4 Answers

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.

like image 36
Joachim Sauer Avatar answered Oct 16 '22 23:10

Joachim Sauer


  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.

like image 35
Rakshit Pai Avatar answered Oct 17 '22 00:10

Rakshit Pai


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

like image 26
Sandip Gopani Avatar answered Oct 17 '22 01:10

Sandip Gopani


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.

like image 69
Guffa Avatar answered Oct 17 '22 01:10

Guffa