This article systematically explains the DOCTYPE element. At the same time, I verified a lot of information. Because the information on the Internet is relatively messy, I redefined it after collecting and sorting it. For example, the definition of the DOCTYPE element is mainly divided into basic knowledge and advanced knowledge. .Basic knowledge explains basic DOCTYPE knowledge. A lot of advanced knowledge comes from the Internet, mainly some practical application skills.
DOCTYPE is the abbreviation of Document Type. The element is used to declare the Document Type Declaration (DTD) of a page. This element declaration is located at the forefront of the document. Before the tag. By confirming the DTD of the page, you can also determine which W3C specification the page uses (such as HTML or XHTML specification).
The correct translation of W3C specifications should be W3C Recommendations. In the eyes of many designers, W3C is the standard. But many people have only a partial understanding of it. The HTML specifications and XHTML specifications in the current W3C specifications are listed below. The relationship between HTML and XHTML will be explained later:
|
Recommended
|
||||||||
HTML 3.2 | January 14, 1997 | ||||||||
HTML 4.0 | May 24, 1998 | ||||||||
HTML 4.01 | December 24, 1999 |
Specifications |
Draft/Proposal |
Recommended |
January 26, 2000 |
||
August 1, 2002 |
||
May 31, 2001 |
||
April 10, 2001 |
||
July 5, 2006 |
||
December 19, 2000 |
||
July 5, 2006 |
||
October 14, 2003 |
||
February 16, 2007 |
||
September 20, 2006 |
||
August 1, 2002 |
||
October 14, 2003 |
||
March 14, 2006 |
||
February 22, 2007 |
||
July 26, 2006 |
||
June 27, 2001 |
||
September 13, 2002 |
XHTML can be regarded as the latest HTML specification and is an XML application that can be smoothly migrated from HTML 4.01. The W3C's first step in refactoring HTML 4.01 to XML led to the birth of XHTML 1.0. XHTML 1.0 relies on the semantics provided by HTML 4.01 tags.
The page file declares different DTDs through the
HTML 4.01 specifies three document types: Strict, Transitional, and Frameset.
Use this type if you need clean markup without clutter in the presentation layer. Please use with Cascading Style Sheets (CSS):
http://www.w3.org/TR/html4/strict.dtd ">
Transitional DTD can contain rendering attributes and elements that the W3C expects to be moved into style sheets. Use this type if your readers are using browsers that don't support Cascading Style Sheets (CSS) and you have to use HTML's rendering features:
http://www.w3.org/TR/html4/loose. dtd">
The Frameset DTD should be used for documents with frames. The Frameset DTD is equivalent to the Transitional DTD, except that the frameset element replaces the body element:
http://www.w3.org/TR/html4/frameset. dtd">
XHTML 1.0 specifies three XML document types: Strict, Transitional, and Frameset.
Use this type if you need clean markup without clutter in the presentation layer. Please use with Cascading Style Sheets (CSS):
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1 /DTD/xhtml1-strict.dtd">
Transitional DTD can contain rendering attributes and elements that the W3C expects to be moved into style sheets. Use this type if your readers are using browsers that do not support Cascading Style Sheets (CSS) and you have to use the rendering features of XHTML:
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd">
When you wish to use a framework, use this DTD!
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1 /DTD/xhtml1-frameset.dtd">
HTML Top Element Availability "Registration//Organization//Type Tag//Definition Language" "URL"
Top-level element: Specifies the type of top-level element declared in the DTD. This corresponds to the declared SGML document type. Default is HTML.
Availability: Specifies whether the Formal Public Identifier (FPI) is a publicly accessible object or a system resource. The value can be PUBLIC or SYSTEM.PUBLIC by default. Represents a publicly accessible object. SYSTEM represents system resources, such as local files or URLs.
Registration: Specifies whether the organization is registered by the International Organization for Standardization (ISO).
is the default, indicating that the organization name has been registered.
- Indicates that the organization name is not registered. The Internet Engineering Task Force (IETF) and the World Wide Web Consortium (W3C) are not registered ISO organizations.
Organization: Specify the name of the group or organization responsible for the creation and maintenance of the DTD referenced by the !DOCTYPE declaration, i.e. the OwnerID. IETF is IETF. W3C is W3C.
Type: Specifies the public text class, that is, the type of object being referenced. Default is DTD.
tag: Specify a public text description, that is, a unique descriptive name for the public text being referenced. A version number can be attached at the back. Default is HTML.
Definition: Specifies the document type definition.
Frameset Frameset documentation.
Strict excludes all representative attributes and elements that W3C experts want to phase out because the style sheet is already well established.
Transitional contains all contents except frameSet elements.
Language: Specifies the public text language, the natural language encoding system used to create the referenced object. The language definition has been written as an ISO 639 language code (uppercase two letters). EN default. English.
URL: Specifies the location of the referenced object.
If you want to check whether your page content complies with the standards declared in DOCTYPE, you can use the verification tool provided by W3C:
Modern browsers include different rendering modes designed to support both web pages that adhere to W3C standards and web pages designed for older browsers. Among them, Standards mode (that is, strict rendering mode) is used to render web pages that comply with the latest standards, while Quirks (inclusive) mode (that is, loose rendering mode or compatibility mode) is used to render web pages designed for traditional browsers. . In addition, note that Mozilla/Netscape 6 adds a new Almost Standards mode to support web pages designed for an older version of the standard.
In theory, this should be a very intuitive switch. If the element of the page indicates that the page conforms to a standard (such as XHTML1.0), the browser will switch to Standards mode. If doctype is not specified, or HTML 3.2 and older is specified, the browser switches to Quirks mode. This way, the browser can correctly display standards-compliant documents without completely abandoning older, non-standard web pages. But there will be the following situations:
In the complete doctype declaration, include the URL of the corresponding document type definition (DTD) file. If the URL is missing, or a relative path is specified (rather than a fully qualified Internet address), most browsers will enter Quirks mode, regardless of the mode specified by the doctype declaration.
Browsers are very sensitive to the form and format of doctype declarations. If a malformed doctype cannot be recognized, it will be forced into Quirks mode (it is recommended to copy and paste a known correct doctype into the document, and Not typing it in person). A common reason for a malformed doctype is a missing space between the first part of the doctype and the URL. Folding a two-line doctype into a single line often loses the space.
When browsers handle transitional doctypes, inconsistencies are most likely to occur. IE and Opera use Standards mode; Netscape 6 and older versions of Safari use Quirks mode; Netscape 7, Mozilla 1, and newer versions of Safari use Netscape's Almost Standards mode, which is a more fault-tolerant version of Standards mode.
There are also inconsistencies in how browsers handle unrecognized doctypes. IE and Opera will enter Standards mode; in other words, it assumes that the unrecognized doctype is a new standard that has not yet been integrated into the browser. Netscape 6, on the other hand, switches to Quirks mode when it encounters an unrecognized doctype.
Doctype switching may be an effective way to get the browser into the correct rendering mode and display the web page correctly, provided that you notice the inconsistencies in various browsers and can proactively avoid various problems.
1. Immediately following the above DOCTYPE declaration is an XHTML namespace declaration, placed in the enhanced element, written as:
http://www.w3.org/1999/xhtml">
2. Since XHTML 1.0 pages are legal XML documents, and XML is case-sensitive for tags and attributes, for the sake of simplicity, all tags and attributes in XHTML 1.0 pages must use lowercase.
Some free tools, such as HTML Tidy (http://tidy.sourceforge.net/), can help you automatically convert tags and attributes to lowercase.
3. Declare the language used in the page by adding a element to the element.
4. In XHTML, all attributes must be quoted.
Some free tools, such as HTML Tidy (http://tidy.sourceforge.net/), can help you automatically add quotes to all attributes.
5. In XHTML, all attributes must have a value.
cannot be written like in HTML 4.0:
should be written as:
6. In XHTML, all tags must be closed.
There are two ways to close tags. Tags containing content are closed with a closing tag, and empty tags are followed by a space and "/". For example:
This is acceptable HTML and it is also valid XHTML.
7. Do not use "--" in comment content.
"--" can only be used at the beginning and end of XHTML comments, and cannot appear in the content of the comment. The following writing methods are not allowed:
8. HTML encode all special symbols.
The three specifications of W3C's XHTML/CSS/DOM form a complete and rigorous system. I call these three specifications the "incarnation of the Trinity" in the Web world. These three specifications represent the structure, presentation and behavior of the Web page respectively. Strictly dividing Web pages into these three layers, and trying to make the content of each layer independent of each other, will help improve the reusability and modularity of the page, and significantly reduce the cost of page production, maintenance, and modification. In order to achieve the above layered goals, XHTML should be written to contain only structure-related markup (elements and attributes). Therefore, you should get used to using Strict type DTD and abandon those tags with expressive implications as soon as possible (these tags are marked as Deprecated in the HTML 4.0 specification, that is, "deprecated", and will be completely abandoned in future versions of XHTML); Abandon the old table-based layout method as soon as possible and adopt a complete CSS layout.
The Definitive Guide to HTML and XHTML, by Chuck Musciano & Bill Kennedy.
"XHTML Tutorial", by Chelsea Valentine & Chris Minnick.
"Website Refactoring" by Jeffrey Zeldman.
Author: Zhang Ziqiu
Source: http://www.cnblogs.com/zhangziqiu/