Doctype role? How to distinguish between strict mode and promiscuous mode? What's the point?
- The declaration must be the first line of the HTML document, before the tag.
- A declaration is not an HTML tag; it is an instruction to the web browser as to which version of HTML the page was written with.
- Strict mode typography and JS work to the highest standard supported by the browser.
- DOCTYPE not present or malformed will cause the document to render in promiscuous mode
- In promiscuous mode, pages are displayed in a loose backwards compatible manner. Emulates the behavior of older browsers to prevent sites from not working.
Doctype document type This tag declares three DTD types, representing strict, transitional, and frame-based HTML documents.
- HTML5 has only one
<!DOCTYPE html>
- HTML 4.01 specifies three document types: Strict, Transitional, and Frameset.
- XHTML 1.0 specifies three XML document types: Strict, Transitional, and Frameset.
- Standards mode (aka strict rendering mode) is used to render web pages that follow the latest standards, while Quirks
- (Inclusive) mode (aka loose rendering mode or compatibility mode) is used to render web pages designed for legacy browsers.
Knowledge point: HTML commonly used DOCTYPE declaration
# HTML 5
<!DOCTYPE html>
# HTML 4.01 Strict
该 DTD 包含所有 HTML 元素和属性,但不包括展示性的和弃用的元素(比如 font)。不允许框架集(Framesets)。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
# HTML 4.01 Transitional
该 DTD 包含所有 HTML 元素和属性,包括展示性的和弃用的元素(比如 font)。不允许框架集(Framesets)。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
# HTML 4.01 Frameset
该 DTD 等同于 HTML 4.01 Transitional,但允许框架集内容。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
Knowledge point: DOCTYPE declaration commonly used in XHTML
# XHTML 1.0 Strict
该 DTD 包含所有 HTML 元素和属性,但不包括展示性的和弃用的元素(比如 font)。不允许框架集(Framesets)。必须以格式正确的 XML 来编写标记。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
# XHTML 1.0 Transitional
该 DTD 包含所有 HTML 元素和属性,包括展示性的和弃用的元素(比如 font)。不允许框架集(Framesets)。必须以格式正确的 XML 来编写标记。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
# XHTML 1.0 Frameset
该 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
该 DTD 等同于 XHTML 1.0 Strict,但允许添加模型(例如提供对东亚语系的 ruby 支持)。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">