The role of doctype in HTML and the detailed explanation of several types

1. Definition and role of DOCTYPE tag

<!DOCTYPE> is used to declare the current HTMl version, used to tell the web browser which HTML or XHTML specification the document uses to parse the page, so that the browser can understand the page content more accurately and display the content effect better!

Second, the characteristics of the DOCTYPE label

1. The <!DOCTYPE> tag has no end tag;

2. The <!DOCTYPE> declaration is supported by all major browsers;

3. The <!DOCTYPE> declaration is not an HTML tag and can be case-insensitive in HTML5;

4. The <!DOCTYPE> declaration must be at the front of the HTML document, before the <html> tag;

Note: HTML4.01 is based on SGML (Standard Generalized Markup Language), and a DTD (document type definition) needs to be referenced with the <!DOCTYPE> statement to ensure that the browser parses the web page content according to the markup rules specified by the DTD! HTML5 is not based on SGML, so there is no need to specify a DTD.

3. DOCTYPE and browser mode

 1. The effect of declaration or not

There is no content in front of the <!DOCTYPE> declaration. If there is any other content (except spaces), the browser will enable the weird mode to render the web page under IE; if the browser enters the weird mode, it will parse and render in its own way. page. Then, under different browsers, the displayed style effects will be inconsistent.

If the document DOCTYPE declaration is not written, the browser will not be able to know the type of the HTML or XHTML document, and will also enter the weird mode; and the version below IE6 will always enter the weird mode;

However, as long as we make the correct declaration of the document DOCTYPE, the browser will enter the standard mode; the browser will parse and render the page according to the W3C standard, then, in all browsers, the displayed style effect will remain the same. Therefore, the <!DOCTYPE> declaration is still necessary.

2. Standard Mode and Compatibility Mode

If the document is in standards mode, the typesetting and JS operation modes of the document are run according to the highest standard supported by the browser; in compatibility mode, the page is displayed in a loose backward compatible way, simulating the behavior of old browsers to prevent Site not working.

4. Common declaration types of DOCTYPE

There are 8 common declaration types of <!DOCTYPE> in HTML, 1 for html5, 3 for HTML 4.01 and XHTML 1.0, and 1 for XHTML 1.1. They are written as follows:

1.HTML5 <!DOCTYPE> declaration – “<!doctype html>

2. HTML 4.01 and XHTML 1.0

strict contains all HTML…

The post The role of doctype in HTML and a detailed explanation of several types first appeared on Lenix Blog .

This article is reprinted from
This site is for inclusion only, and the copyright belongs to the original author.