html is the common language for publishing hypertext on the World Wide Web [1]. From 1982, tim berners-lee simplified the original definition of sgml to the release of xhtml1.1 specification in 2001, html has become an international standard with multiple versions [2]. The specifications of each version are defined in a machine-readable language that describes legal structures, elements and attributes, which is the document type definition, referred to as dtd.
Related articles: html code learning: abbreviation of doctype
dtd describes the document type declaration (dtd declaration, referred to as doctype[3]) at the front of the html document. It is the contact document and the dtd directive. For example, the doctype of html4.01 strict is:
<!doctype html public -//w3c//dtd html 4.01//en http://www.w3.org/tr/html4/strict.dtd>It specifies the html version of the document, which is the information most needed when a tool such as a browser parses a document. For example, the w3c verification tool can check syntax and point out errors based on it.
The early browsers' error implementation of standards, the large number of private extensions, the confusion of the early standards themselves, etc., led to the documents at that time neither doctype nor direct references to dtd, and also made it difficult for new standards to be applied and popularized because browsers cannot distinguish them. In order to deal with web pages created according to web standards and web pages created according to outdated practices, todd fahrner proposed the came up with a toggle method in 1998, which allows the browser to provide two sets of rendering modes: that is, there is a complete doctype document used to parse using the w3c standard, otherwise it is parsed in the old way.
This method is practical and simple and effective. Two years later, the first time it was used on the Mac version of IE, and soon other browser manufacturers adopted it, which gave birth to doctype sniffing (doctype sniffing or doctype switching). The browser uses it to decide whether its engine should adopt standard mode, quasi-standard mode or quirk mode, which will have a very big impact on the parsing of html and css, the layout of css and javascript scripts [5]. There is no doubt that we should adopt the standard model as much as possible.
Although html5 is still in the draft, the latest browsers firefox3.5, chrome2, safari4 and ie8 have begun to support some features, especially the release of Google Wave has set off a new climax in promoting the practice of html5. html5 is not based on sgml nor does it have dtd, but for forward compatibility it accepts the fact that doctype sniffs, defining that doctype is the only mode conversion declaration in text/html, except that it is of no use. Its doctype is so concise: <!doctype html>[6] .
It is worth mentioning that in order to solve the problem of forward compatibility, ie8 adopts x-ua-compatible declaration [7], which leads to the rendering mode of the browser in ie8 that not only depends on doctype sniffing but also on x-ua-compatible declaration. This not only leads to more complex pattern judgments [8], but also violates the progressive enhancement idea of web design [9].
On the road to web standards, we need not only forward compatibility with realism, but also backward compatibility with idealism. This is the hope to ensure that our web can work normally in the future. With the idea of standard, simplicity and gradually enhancing, the best solution for our page now is perhaps:
<!doctype html>…<meta http-equiv=x-ua-compatible content=ie=edge>…Notes: