I was asked today if I have any detailed understanding of the <!DOCTYPE> tag? , I was stunned for a moment, because I saw it at the beginning that I suggested using XHTML Transitional DTD on W3cschool, and then I obediently set Dreamweaver's HTML document type to XHTML 1.0 Transitional by default. It has been used for granted until now. People are really the lazy thing. The older they grow, the lazier they get. Many things are subconsciously taken for granted. Since I have been asked, I went to find information and summarized it. Let's take it as a note~~
Definition of <!DOCTYPE> :The <!DOCTYPE> declaration is located at the frontmost position in the document, before the <html> tag. This tag tells the browser which HTML or XHTML specification to use for the document.
This tag can declare three DTD types, representing strict versions, transition versions, and framework-based HTML versions. (If the tags in the document do not follow the DTD specified by the doctype declaration, this document may not be displayed correctly in the browser in addition to not passing code verification.)
Usage of <!DOCTYPE> :<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> Analysis: In the above declaration, the root element of the document is declared as html, which is defined in DTD with the public identifier defined as -//W3C//DTD XHTML 1.0 Strict//EN. The browser will understand how to find a DTD that matches this public identifier. If not found, the browser will use the URL after the public identifier as the location to look for the DTD.
-: Indicates that the organization name is not registered. The Internet Engineering Task Force (IETF) and the World Wide Web Association (W3C) are not registered ISO organizations.
+ is the default, indicating that the organization name is registered.
DTD: Specifies the public text class, that is, the object type referenced. Default is DTD.
HTML: Specifies a public text description, that is, a unique descriptive name for the referenced public text. Version number can be included later. Default is HTML.
URL: Specifies the location of the referenced object.
Strict: Exclude all representative attributes and elements that W3C experts want to phase out.
Three HTML document types:HTML 4.01 specifies three document types: Strict, Transitional, and Frameset.
a) If you need clean markup to avoid confusion in presentation, use HTML Strict DTD type:
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd>
b) Transitional DTD can contain rendering attributes and elements that W3C expects to move into style sheets. If the user uses a browser that does not support cascading style sheets (CSS) so that you have to use the rendering attributes of HTML, use the Transitional DTD type:
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd>
c) Frameset DTD is used for documents with frames. Except for the frameset element that replaces the body element, Frameset DTD is equivalent to Transitional DTD:
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Frameset//EN http://www.w3.org/TR/html4/frameset.dtd>
Three XML document types :XHTML 1.0 specifies three XML document types: Strict, Transitional, and Frameset.
a) If you need clean markup to avoid confusion in presentation, use the XHTML Strict DTD type:
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
b) Transitional DTD can contain rendering attributes and elements that W3C expects to move into style sheets. If the user uses a browser that does not support cascading style sheets (CSS) so that you have to use the rendering attributes of HTML, use the Transitional DTD type:
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
c) Frameset DTD is used for documents with frames. Except for the frameset element that replaces the body element, Frameset DTD is equivalent to Transitional DTD:
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Frameset//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd>
Select the correct doctype :In order to obtain the correct doctype declaration, the key is to make dtd correspond to the standards followed by the document.
For example, assuming that the document follows the xhtml 1.0 strict standard, the doctype declaration of the document should refer to the corresponding dtd.
On the other hand, it is inappropriate if the doctype declaration specifies xhtml dtd, but the document contains old-style html tags; similarly, it is also inappropriate if the doctype declaration specifies html dtd, but the document contains xhtml 1.0 strict tags.
If no valid doctype declaration is specified, most browsers will use a built-in default dtd. In this case, the browser will use the built-in dtd to try to display the tags you specified (but this is what you do when the page is written too badly).
I looked at JD.com, Taobao, and Blog Park, and I used this (I have always used this):
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
However, I found that Baidu and Google used <!doctype html>, so I carefully checked the information and found that HTML5 was also used directly, but because HTML 5 is not based on SGML, so there is no need to do DTD
References, but doctype is needed to regulate the behavior of the browser (let the browsers run the way they should).
It is recommended to use <!doctype html> directly in the future. If you use <!doctype html>, the standard compatibility mode of the browser will be enabled. In the standard compatibility mode, it cannot be guaranteed to be compatible with other versions (before IE6, just ignore it). Internet Explorer. The rendering behavior of the document may be different from the future Internet Explorer, but please feel free to use it~~
Tips :XHTML 1 is the XMLization of HTML 4.01, which is a format that is not forward compatible.
The doctype in HTML 4.01 requires references to DTDs because HTML 4.01 is based on SGML.
SGML specifies a standard format for embedding description tags in documents and specifies a standard method for describing document structure. The HTML format currently used on WEB is an SGML document that uses a fixed set of tags.