HTML is the universal language for publishing hypertext on the World Wide Web [1]. From 1982 when Tim Berners-Lee simplified SGML to establish the original definition of HTML to the release of the XHTML1.1 specification in 2001, HTML has become an international standard with multiple versions [2]. Each version of the specification is defined in a machine-readable language, which describes the legal structure, elements and attributes. This is the Document Type Definition (DTD).
DTD describes the document type declaration (DTD declaration, referred to as doctype[3]) located at the front of the HTML document. It is the link between the document and the DTD instruction. 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 indicates the version of HTML used by the document, which is the most important information that tools such as browsers need when parsing the document. For example, W3C's validation tools can use it to check syntax and point out errors.
The incorrect implementation of standards in early browsers, the proliferation of private extensions, and the confusion of the early standards themselves for forward compatibility resulted in documents at that time having neither doctypes nor direct references to DTDs, which also made it difficult to implement new standards. gained adoption and popularity because browsers couldn't tell them apart. In order to deal with web pages created according to Web standards and web pages created according to old practices, Todd Fahrner proposed the "came up with a toggle" method in 1998 [4], which allows the browser to provide two sets of rendering modes: that is, with a complete doctype Documents are parsed using W3C standards, otherwise they are parsed the old way.
This method is practical, simple and effective. Two years later, it was first used on the Mac version of IE, and other browser manufacturers soon adopted it. This 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 quirks mode, which will have a great impact on HTML and CSS parsing, CSS layout and JavaScript scripts [5]. There is no doubt that we should use the standard model as much as possible.
Although HTML5 is still in draft, the latest browsers Firefox3.5, Chrome2, Safari4 and IE8 have begun to support some features. In particular, the release of Google Wave has set off a new upsurge in promoting HTML5 practice. HTML5 is not based on SGML and does not have a DTD, but for the sake of forward compatibility, it accepts the fact of doctype sniffing and defines that doctype is the only mode conversion statement in text/html, and has no other use. Its doctype is so concise: <!doctype html>[6].
It is worth mentioning that IE8 adopts the X-UA-Compatible statement [7] to solve forward compatibility. As a result, the browser's rendering mode in IE8 depends not only on doctype sniffing but also on the X-UA-Compatible statement. This Not only does it make pattern judgment more complex [8], but it also violates the idea of progressive enhancement in web design [9].
On the road to web standards, we not only need forward compatibility full of realism, but also backward compatibility full of idealism. This is the hope to ensure that our web can work properly in the future. Under the ideas of standards, simplicity and gradual enhancement, the best solution for our page now may be:
<!doctype html> … <meta http-equiv="X-UA-Compatible" content="IE=Edge"> …
Note:
[1] HTML is the lingua franca for publishing hypertext on the World
Wide Web
[2] http://zh.wikipedia.org/wiki/Html
[3] DTD declaration was often called Document Type Declaration in previous specifications.
It is easy to be confused with DTD.
[4] http://web.archive.org/web/20030212115103/http://www.geocrawler.
com/archives/list-name.mbox/123/1998/7/0/1037920/
[5]Activate browser mode with doctype
[6] http://www.w3.org/TR/html5/syntax.html#the-doctype
[7] Beyond document types, web standardization forward compatible with IE8
[8] http://dancewithnet.com/2009/06/14/activating-browser-modes
-with-doctype/#ie8modes
[9] Does the future of web standards depend on browser technology?
Original text: http://ued.koubei.com/?p=928