What's a doctype do?
2014-08-26 15:54
162 查看
来源:w3c
8.1.1 The DOCTYPE
A DOCTYPE is a required preamble.DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications. Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the
relevant specifications.
A DOCTYPE must consist of the following components, in this order:
A string that is an ASCII case-insensitive match
for the string "
<!DOCTYPE".
One or more space characters.
A string that is an ASCII case-insensitive match
for the string "
html".
Optionally, a DOCTYPE legacy string or an obsolete
permitted DOCTYPE string (defined below).
Zero or more space characters.
A ">" (U+003E) character.
In other words,
<!DOCTYPE html>, case-insensitively.
For the purposes of HTML generators that cannot output HTML markup with the short DOCTYPE "
<!DOCTYPE html>", a DOCTYPE
legacy string may be inserted into the DOCTYPE (in the position defined above). This string must consist of:
One or more space characters.
A string that is an ASCII case-insensitive match
for the string "
SYSTEM".
One or more space characters.
A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the quote mark).
The literal string "
about:legacy-compat".
A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step labeled quote mark).
In other words,
<!DOCTYPE html SYSTEM "about:legacy-compat">or
<!DOCTYPE html SYSTEM 'about:legacy-compat'>, case-insensitively except
for the part in single or double quotes.
The DOCTYPE legacy string should not be used unless the document is generated from
a system that cannot output the shorter string.
To help authors transition from HTML4 and XHTML1, an obsolete permitted DOCTYPE string can be inserted into the DOCTYPE (in the position defined above). This string
must consist of:
One or more space characters.
A string that is an ASCII case-insensitive match
for the string "
PUBLIC".
One or more space characters.
A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the first quote mark).
The string from one of the cells in the first column of the table below. The row to which this cell belongs is the selected row.
A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step labeled first quote mark).
If a system identifier is used,
One or more space characters.
A U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (the third quote mark).
The string from the cell in the second column of the selected row.
<
4000
li style="margin:0px;padding:0px;">A matching U+0022 QUOTATION MARK or U+0027 APOSTROPHE character (i.e. the same character as in the earlier step labeled third quote mark).
Public identifier | System identifier | System identifier optional? |
---|---|---|
-//W3C//DTD HTML 4.0//EN | http://www.w3.org/TR/REC-html40/strict.dtd | Yes |
-//W3C//DTD HTML 4.01//EN | http://www.w3.org/TR/html4/strict.dtd | Yes |
-//W3C//DTD XHTML 1.0 Strict//EN | http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd | No |
-//W3C//DTD XHTML 1.1//EN | http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd | No |
permitted DOCTYPE string is an obsolete permitted DOCTYPE. Authors should not use obsolete
permitted DOCTYPEs, as they are unnecessarily long.
Why?
Why specify a doctype? Because it defines which version of (X)HTML your document is actually using, and this is a critical piece of information needed by some tools processing the document.For example, specifying the doctype of your document allows you to use tools such as the Markup Validator to check the syntax of your (X)HTML. Such tools won't
be able to work if they do not know what kind of document you are using.
But the most important thing is that with most families of browsers, a doctype declaration will make a lot of guessing unnecessary, and will thus trigger a "standard" rendering mode.
参考:http://www.w3.org/QA/2002/04/valid-dtd-list.html
相关文章推荐
- what's this , it's a ruler
- What's a Heap?(什么是堆)
- What's a debugger?
- What's a namespace?
- In C++, what’s a vtable and how does it work?
- What's a Document Type Definition (DTD) and ...
- What’s a pre-borrow?
- (.NET Framework) What’s a “Strong Named” assembly?
- (原創) What's a good OO design? (OO)
- What's a J2EE Dev To Do?
- What's a Declaration? What's a Definition?
- What's a ‘sequence point’
- What's a Statement?
- What the hell is Rotate?
- What does enumerable mean?
- setEnabled() vs setClickable(), what is the difference?
- what 's difference between android system user and linux root user
- What are the 10 algorithms one must know in order to solve most algorithm challenges/puzzles?
- POJ 3130 & ZOJ 2820 How I Mathematician Wonder What You Are!(半平面相交 多边形是否有核)
- HDU 1075-What Are You Talking About(map)