<!DOCTYPE>

HTML <!DOCTYPE> Declaration

The <!DOCTYPE> declaration is the first line of the code in HTML or XHTML document. It specifies the HTML version used in the document. Each HTML document should start with this declaration: so the browsers will render the page compliant with HTML standards. In HTML 4.01, this declaration refers to a Document Type Definition (DTD), which specifies the structure and the legal elements of an XML document.

The <!DOCTYPE> is declared before the <html> tag. The declaration is not case sensitive.

Syntax

Syntax (语法)

[Root element] [Publicity] "[Registration]//[Organization]//[Type] [Name]//[Language]" "[URL]">

<!DOCTYPE> Parameters

<!DOCTYPE> Parameters

Root element — a parent element that contains all the other elements. For HTML it is the <html> tag.

Publicity — the document can be PUBLIC or SYSTEM (local files, for example). For HTML/XHTML the value is PUBLIC. (公开—文档可以是公共的,也可以是系统的(例如本地文件)。对于HTML/XHTML ,值为PUBLIC。)

Registration - can have two values: plus (+) - the developer is registered in ISO (International Organization for Standardization) and - (minus) - the developer is not registered. For W3C, the value is set to “-”.

Organization — the name of DTD developer. The developer of HTML/XHTML is W3C, and its name is declared in <!DOCTYPE>.

Type — the type of the document. For HTML/XHTML the value is DTD. (类型—文档的类型。对于HTML/XHTML ,值为DTD。)

Name — unique identifier describing DTD. (名称—描述DTD的唯一标识符。)

Language — the language of the document (two letters in uppercase). For HTML/XHTML the language is English (EN). (语言—文档的语言(两个大写字母)。对于HTML/XHTML ,语言为英语( EN )。)

URL — the URL of the document type description (e.g. https://www.w3.org/TR/html4/loose.dtd).

Types of the <!DOCTYPE> Declaration for HTML

Types of the <!DOCTYPE> Declaration for HTML

There are three types of the <!DOCTYPE> declaration for HTML:

Strict - contains all HTML elements and attributes. However, the presentational or deprecated elements are not included. (严格-包含所有HTML元素和属性。但是,不包括表示式或不推荐使用的元素。)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/html4/strict.dtd">

Transitional - contains all HTML elements and attributes, including presentational and deprecated elements. Frames are not allowed. (过渡-包含所有HTML元素和属性,包括呈现元素和弃用元素。不允许使用框架。)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">

Frameset - is equal to Transitional, but allows the use of frames. (帧集-等于过渡,但允许使用帧。)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "https://www.w3.org/TR/html4/frameset.dtd">

There is only one version of declaration for HTML 5. (HTML 5的声明只有一个版本。)

<!DOCTYPE html>

Example of the HTML <!DOCTYPE> declaration:

<!DOCTYPE html>
<html>
 <head>
   <title>Title of the document</title>
 </head>
 <body>
   <h2>Elements example</h2>
   <p>This is some paragraph.</p>
   <p>This is another paragraph <br/> with  line break.</p>
 </body>
</html>

Result

Types of the <!DOCTYPE> Declaration for XHTML

Types of the <!DOCTYPE> Declaration for XHTML

Here you can find types of the <!DOCTYPE> declaration for XHTML.

XHTML 1.0 Strict

This DTD includes all the HTML elements and attributes, except presentational or deprecated elements. This DTD doesn’t allow frameworks. (此DTD包括所有HTML元素和属性,呈现元素或弃用元素除外。此DTD不允许使用框架。)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

XHTML 1.0 Transitional

This DTD includes all the HTML elements and attributes, as well as presentational and deprecated elements. Framesets are not allowed. (此DTD包括所有HTML元素和属性,以及呈现和弃用的元素。不允许使用框架集。)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

XHTML 1.0 Frameset

This DTD is similar to XHTML 1.0 Transitional, but framesets are allowed. (此DTD类似于XHTML 1.0 Transitional ,但允许使用框架集。)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

XHTML 1.1

This DTD is equal to XHTML 1.0 Strict, but allows adding modules (e.g., to provide Ruby support for East-Asian languages). (此DTD等于XHTML 1.0 Strict ,但允许添加模块(例如,为东亚语言提供Ruby支持)。)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部