We declare DOCTYPE in HTML generally has the following types:
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd>
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd>
Yes, there are HTML and XHTML here, and there are also Transitional and Strict. As the name suggests, XHTML means that this document is written in the XML format, and HTML means that this document is written in the HTML format. Transition means that this document meets the requirements of Transitional.dtd or loose.dtd, while Strict means that this document meets the requirements of strict.dtd. But in fact, we often have the following misunderstandings:
(1) My document is declared XHTML, then my document must be exactly in XML format.
(2) My document is declared Strict, so my document must be rendered in the Strict Mode way, otherwise, it is rendered in the Quirks Mode way.
Both of these understandings are very direct, but they are wrong, and we often make such mistakes.
First, the document is declared as XHTML and HTML, and has no direct correlation with the document's Parse (i.e., the browser's analysis of the document). In fact, how the browser Parse document depends on what format the server provides the document. Generally speaking, there are two ways: text/html and application/xhtml xml. Only documents provided in application/html xml can be parse in XML. However, due to the historical reasons of the browser, not all browsers support application/xhtml xml format documents. Versions before IE7 (including IE7) cannot support this format. If IE7 encounters a document in this format, it will prompt the user to save as other files. Considering the widespread use of IE, most of the documents are currently provided in text/html. Documents provided in text/html are Parse according to the semantics of HTML. Everyone knows that HTML is very fault-tolerant. Even if the TAG in your document is not closed correctly, the HTML can be displayed correctly. Therefore, if your XHTML is provided in text/html (in most cases), even if you declare XHTML in DOCTYPE, your document is not Parse in XML format, so it cannot guarantee that your document is strictly in accordance with XML specifications. In fact, many experts suggest that if your document is not provided in the form of application/xhtml xml, then you should declare it as HTML.
Secondly, the way the browser renders your document is not determined by the DTD you declare. In fact, if you declare DOCTYPE and DTD, your document is rendered in Strict Mode (or Standard Mode, many browsers also include Almost Standard Mode, and there is no distinction here). For documents without DOCTYPE, the Quirks Mode is used to render. Therefore, the browser's Render mode has no direct relationship with the DTD you declared.
Finally, whether you declare it as Strict.dtd or Transitional.dtd, there seems to be no difference in current browsers. Strict.dtd is much stricter than Transitional.dtd or loose.dtd, and many elements cannot be used in strict.dtd. However, due to browser compatibility, even if you declare Strict.dtd in DOCTYPE, the browser can still display your document correctly when encountering elements that are not allowed in strict.dtd. I guess the browser doesn't take DTD into consideration. For example, the TAG of iframe does not exist in strict.dtd, but even if your DOCTYPE declares strict.dtd and then uses the TAG of iframe, the browser (including IE7, IE8, FF3.0, Safari 3.0) can correctly display your document. The browser does not Parse your document according to the DTD you declared. At present, it can ensure that your document complies with strict.dtd or Transitional.dtd. It can only be analyzed through some online Validators, such as W3C Validator. The browser cannot provide you with good support. Of course, in fact, if you can write your document strictly according to the DTD you declare, it is best, so that your document will not produce errors when the browser strictly abides by DTD in the future.
therefore,
(1) If your document is provided in text/html, then you should declare it as HTML. If you want IE7 to display correctly, then you should do this even more.
(2) If your document is declared as XHTML, then you should provide it in the form of application/html xml.
(3) Try to declare DOCTYPE and DTD in front of your document, so as to ensure that you do not use Quirks Mode to render the document.
(4) If you declare DTD, then you must write your document strictly in accordance with the requirements of DTD. Especially if you declare Strict.dtd, then you should be careful about which elements are not usable.
Note: Over time, browser support for HTML and XHTML, Strict.dtd and Transitional.dtd will be better. If your browser is much higher than IE7, IE8, FF 3.0 and Safari 3.0, then you should pay attention to the applicability of this article.