Detailed explanation of DOCTYPE element full version_HTML/Xhtml_Web page production

WBOY
Release: 2016-05-16 16:41:22
Original
1664 people have browsed it

1. Overview

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.

2. Definition

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).

Three.W3C specifications

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:

W3C HTML Specification and Timeline

规范

推荐

HTML 3.2

1997年1月14日

HTML 4.0

1998年5月24日

HTML 4.01

1999年12月24日

Specification

Recommended

HTML 3.2 January 14, 1997
HTML 4.0 May 24, 1998
HTML 4.01 December 24, 1999
W3C XHTML Specification and Timeline

Specifications

Draft/Proposal

Recommended

XHTML 1.0

January 26, 2000

XHTML 1.0 Revision

August 1, 2002

XHTML 1.1

May 31, 2001

XHTML Modules

April 10, 2001

XHTML Modules 1.1

July 5, 2006

XHTML Basic

December 19, 2000

XHTML Basic 1.1

July 5, 2006

XHTML Events

October 14, 2003

XHTML Events 2

February 16, 2007

XHTML Print

September 20, 2006

XHTML Media Types

August 1, 2002

XForms 1.0

October 14, 2003

XForms 1.0 (SE)

March 14, 2006

XForms 1.1

February 22, 2007

XHTML 2.0

July 26, 2006

XLink

June 27, 2001

HLink

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.

4. Specifications and DTD

The page file declares different DTDs through the element to tell the browser which HTML or XHTML specification the current page conforms to. Here are only the DTDs related to HTML4.01 and XHTML1.0 specifications:

HTML

HTML 4.01 specifies three document types: Strict, Transitional, and Frameset.


HTML Strict DTD

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 ">


HTML Transitional 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">


Frameset 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

XHTML 1.0 specifies three XML document types: Strict, Transitional, and Frameset.


XHTML Strict DTD

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">


XHTML Transitional 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">


XHTML Frameset 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">

5.DOCTYPE element syntax

Grammar

HTML Top Element Availability "Registration//Organization//Type Tag//Definition Language" "URL"

Explanation of syntax elements

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.

6. Checking Tools

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:

http://validator.w3.org/

Seven.DOCTYPE switching

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:

1. Missing URL or relative URL

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.

2. Wrong-formed doctype

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.

3. Transition doctype

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.

4.Unknown doctype

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.  

8. XHTML usage tips

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.

9. Recommended XHTML related books

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/

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template