Have you carefully understood how to define and use the tag

Time:2021-4-21

preface
Today, I was asked, “have you studied the <! DOCTYPE > label carefully?” , I was stunned for a moment, because at the beginning I saw that it was suggested to use XHTML transitional DTD on w3cschool, and then I obediently set the HTML document type of Dreamweaver to XHTML 1.0 transitional by default. And then, of course, it’s been used all the time. People are really lazy when they grow up. Many things are taken for granted by subconsciousness. Now that I’ve been asked, I’ll look for the information and summarize it. Let’s take notes~~

Definition of <! DOCTYPE >
<! DOCTYPE > The declaration is at the front of the document, in the < html > Before the label. This tag tells the browser which HTML or XHTML specification the document uses.
The tag can declare three DTD types, namely strict version, transitional version and framework based HTML version. (if the markup in the document does not follow the DTD specified in the DOCTYPE declaration, the document may not be displayed correctly in the browser except for 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 “> parsing: in the above declaration, it is declared that the root element of the document is HTML, which is defined in the DTD whose public identifier is defined as” -/ / W3C / / DTD XHTML 1.0 strict / / en “. The browser will know how to find a DTD that matches this public identifier. If not, the browser uses the URL after the public identifier as the location to find the DTD.
-: indicates that the organization name is not registered. IETF and 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 type of object referenced. The default is DTD.
HTML: Specifies the public text description, that is, the unique descriptive name of the quoted public text. The version number can be attached. The 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 the confusion of presentation layer, use HTML strict DTD type:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” ” http://www.w3.org/TR/html4/strict.dtd”>
B) the transitional DTD can contain the rendering attributes and elements that W3C expects to move into the style sheet. If the user uses a browser that does not support cascading style sheets (CSS) and you have to use the rendering features 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 that frameset element replaces 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 types of XML documents
XHTML 1.0 specifies three XML document types: strict, transitional, and frameset.
A) if you need clean markup to avoid the confusion of presentation layer, use 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) the transitional DTD can contain the rendering attributes and elements that W3C expects to move into the style sheet. If the user uses a browser that does not support cascading style sheets (CSS) and you have to use the rendering features 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 that frameset element replaces 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”>

Choose the right DOCTYPE
In order to get the correct DOCTYPE declaration, the key is to make the DTD correspond to the standard that the document follows.
For example, assuming that the document follows the XHTML 1.0 strict standard, the document’s DOCTYPE declaration should refer to the corresponding DTD.
On the other hand, if the DOCTYPE declaration specifies XHTML DTD, but the document contains old style HTML tags, it is inappropriate; similarly, if the DOCTYPE declaration specifies HTML DTD, but the document contains XHTML 1.0 strict tags, it is also inappropriate.
Without specifying a valid DOCTYPE declaration, most browsers use a built-in default DTD. In this case, the browser will use the built-in DTD to try to display the tag you specified (but this is what happens when the page is badly written).
I have a look at Jingdong, Taobao, and the blog park. I use this one all the time
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
But found that Baidu and Google are using“ <! doctype html >” After a closer look at the data, it is found that HTML5 is also used directly, but because HTML5 is not based on SGML, there is no need to modify DTD
Reference, but you need a DOCTYPE to regulate the behavior of the browser (let the browser run as they should).

It is recommended to use “<! DOCTYPE HTML >” directly in the future. If you use <! DOCTYPE HTML >, you will open the browser’s standard compatibility mode. In the standard compatibility mode, you can’t guarantee to keep compatibility with other versions of Internet Explorer (before IE6, ignore it directly). The file rendering behavior may be similar to that of Internet Explorer in the future Different, but please rest assured to use it~~

Tips
XHTML 1 is the XML version of HTML 4.01, which is an incompatible format.
The DOCTYPE in HTML 4.01 needs to reference DTD, because HTML 4.01 is based on SGML.
SGML specifies the standard format of embedding description tags in documents and the standard method of describing document structure. The HTML format currently used on the web is a SGML document with fixed tag set.

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]