Doctype in HTML has two main purposes.
1. Verify the validity of the document
It tells the user agent and validator what DTD this document is written according to. This action is passive. Every time the page is loaded, the browser does not download the DTD and check the validity. It is only enabled when the page is manually verified.
2. Determine the browser's rendering mode
For actual operations, inform the browser which parsing algorithm to use when reading the document. If it is not written, the browser will parse the code according to its own rules, which may seriously affect the html layout. Browsers have three ways to parse HTML documents.
Related Links:
Mode? Standard!
Enable browser mode through Doctype
CS002: DOCTYPE and browser mode analysis
KB001: Compatibility issues and browser kernel and rendering mode
In-depth understanding of browser compatibility mode