Home > Article > Web Front-end > The role of HTML declaration_html/css_WEB-ITnose
In the html page, what is the use of the following line of code?
During a page reconstruction process, I saw such a piece of code in the first line of the static page, followed by a large blank space. I accidentally deleted this line of code when deleting whitespace, and then. . . .
The page that originally displayed normally suddenly became messy and the font style was gone. The key was to put it in IE and see that the layout was completely misaligned. I thought it was a problem with the style, so I spent a long time looking for it. I didn't find the reason. Fortunately, I had a backup of the original file. I took it out and compared it. I found that this line of code was doing something weird, and then I studied it for a while. What is it used for?
The declaration is located at the very front of the document, before the tag. This tag tells the browser which HTML or XHTML specification the document uses.
The role of doctype
The doctype declaration indicates what set of rules the reading program should use to interpret the markup in the document. In the case of web documents, the "reader" is usually a program such as a browser or a validator, and the "rules" are the rules contained in a document type definition (dtd) published by the W3C.
Each DTD includes a series of tags, attributes, and properties that are used to mark the content of the web document; it also includes rules that specify which tags can appear in which other tags. Each web recommendation standard (such as HTML 4 Frameset and XHTML 1.0 Transitional) has its own DTD.
If the tags in the document do not comply with the dtd specified in the doctype declaration, the document may not pass code verification and may not be displayed correctly in the browser. Browsers are more forgiving than validators when it comes to markup inconsistencies. However, incorrect doctype declarations often cause web pages to display incorrectly, or cause them not to display at all.