Html 声明 HTML5 Doctype 的正确方法是什么。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10963135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the correct way to declare an HTML5 Doctype.
提问by user6573
What is the correct way to use start tag when creating with HTML5
使用 HTML5 创建时使用开始标记的正确方法是什么
IE: HTML 4 Strict is like this
IE: HTML 4 Strict 是这样的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
回答by Alex W
The standard has been simplified because the previous doctypes were too cryptic. The new doctype is simply <!DOCTYPE html>
. You may wonder why it is not <!DOCTYPE html5>
but it is simply because it is just an update to the standard of HTML and not a new version of anything. As you can see below, all elements can now have a language attribute.
该标准已被简化,因为以前的文档类型太神秘了。新的文档类型很简单<!DOCTYPE html>
。您可能想知道为什么不是,<!DOCTYPE html5>
但这仅仅是因为它只是对 HTML 标准的更新,而不是任何东西的新版本。如下所示,所有元素现在都可以具有语言属性。
The
<html>
element is the root element of a document. Every document must begin with this element, and it must contain both the<head>
and<body>
elements.It is considered good practice to specify the primary language of the document on this element using the lang attribute.
所述
<html>
元件是一个文件的根元素。每个文档都必须以此元素开头,并且必须同时包含<head>
和<body>
元素。使用 lang 属性在此元素上指定文档的主要语言被认为是一种很好的做法。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
<p>
Jamie was here.
</p>
</body>
</html>
More info: https://dev.w3.org/html5/html-author/#doctype-declaration
更多信息:https: //dev.w3.org/html5/html-author/#doctype-declaration
回答by Kirill Fuchs
you just use
你只是用
<!DOCTYPE html>
<html>
</html>
回答by asmmahmud
回答by gion_13
It's as simple as
就这么简单
<!DOCTYPE html>
回答by Andrew Smallwood
According to the WWW Consortium, the organization responsible setting current web standards, no one has answered this correctly. The current standard for language declaration is
根据负责制定当前 Web 标准的组织 WWW 联盟的说法,没有人正确回答这个问题。语言声明的当前标准是
Alwaysuse a language attribute on the html tag to declare the default language of the text in the page. When the page contains content in another language, add a language attribute to an element surrounding that content. Use the lang attribute for pages served as HTML, and the xml:lang attribute for pages served as XML. For XHTML 1.x and HTML5 polyglot documents, use both together.
W3C HTML Language Tag Page
始终在 html 标签上使用语言属性来声明页面中文本的默认语言。当页面包含另一种语言的内容时,向围绕该内容的元素添加语言属性。对作为 HTML 的页面使用 lang 属性,对作为 XML 的页面使用 xml:lang 属性。对于 XHTML 1.x 和 HTML5 多语言文档,将两者一起使用。
W3C HTML 语言标签页
Here is the answer regarding DOCTYPE declaration
这是关于 DOCTYPE 声明的答案
Use the following markup as a template to create a new HTML document using a proper Doctype declaration. See the list below if you wish to use another DTD.
W3C DOCTYPE Standards
使用以下标记作为模板,使用正确的 Doctype 声明创建新的 HTML 文档。如果您想使用另一个 DTD,请参阅下面的列表。
W3C DOCTYPE 标准
<!DOCTYPE html>
<html>
<head>
<title>An HTML standard template</title>
<meta charset="utf-8" />
</head>
<body>
<p>… Your HTML content here …</p>
</body>
</html>
Hope this helps.
希望这可以帮助。
回答by Mike Sav
You use...
你用...
<!DOCTYPE html>
followed by your HTML tag etc..
其次是您的 HTML 标签等。
回答by ioseb
You only need this:
你只需要这个:
<!DOCTYPE html>
<html>
...
There are several points here. This is supported by all browsers, even old ones like IE6/IE7. All browsers actually nee "html" part from doctype declaration to jump into standards mode.
这里有几点。所有浏览器都支持这一点,甚至是像 IE6/IE7 这样的旧浏览器。所有浏览器实际上都需要 doctype 声明中的“html”部分才能跳转到标准模式。
回答by Sarfraz
<!-- simplified doctype works for all previous versions of HTML as well -->
<!doctype html>
Learning Resource:
学习资源:
回答by Jukka K. Korpela
The start tag <html>
is optional in HTML5, as in HTML 4.01. If used, it must be the first tag. It has different optional attributes: the global attributes of HTML5, and the special manifest
attribute. The most common useful attribute in the <html>
tag is the lang
attribute.
开始标记<html>
在 HTML5 中是可选的,就像在 HTML 4.01 中一样。如果使用,它必须是第一个标签。它有不同的可选属性:HTML5 的全局属性和特殊manifest
属性。<html>
标签中最常见的有用属性是lang
属性。
(The doctype declaration is something quite different, and not a tag at all.)
(文档类型声明完全不同,根本不是标签。)
回答by Panu Logic
The clearest most definitive answer of what the standard says seems to be for HTML 5.3 at:
标准所说的最清晰最明确的答案似乎是针对 HTML 5.3 的:
http://w3c.github.io/html/syntax.html#the-doctype
http://w3c.github.io/html/syntax.html#the-doctype
Note especially the list-items 1 and 3 which specify that the doctype-statement is case-insensitive. Also note the number of spaces inside the statement can vary.
请特别注意列表项 1 和 3,它们指定 doctype-statement 不区分大小写。另请注意,语句内的空格数可能会有所不同。
And note the clause "A DOCTYPE is a required preamble."
并注意“A DOCTYPE 是必需的序言”这一条款。