应被视为必备的 HTML 5 的建议元标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11767755/
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
Suggested meta tags for HTML 5 that should be considered a must have
提问by PeanutsMonkey
I am looking at migrating over pages written in XHTML 1.0 to HTML 5 and am looking at the minimum requirements when including meta
tags in the <head>
element. For example, my current page which is XHTML 1.0 compliant has the following meta
tags
我正在考虑将用 XHTML 1.0 编写的页面迁移到 HTML 5,并考虑在元素中包含meta
标签时的最低要求<head>
。例如,我当前符合 XHTML 1.0 的页面具有以下meta
标签
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta http-equiv="content-language" content="en-us" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="copyright" content="© 2012" />
<meta name="robot" content="noindex, nofollow" />
Are the following sufficient for HTML 5 and can I also include them?
以下内容对于 HTML 5 是否足够,我还可以包含它们吗?
It is also my understanding that the meta
element <meta http-equiv="content-language" content="en-us" />
can now be globally be applied to the <html>
element.
我的理解是meta
元素<meta http-equiv="content-language" content="en-us" />
现在可以全局应用于 <html>
元素。
<html lang="en-us">
<head>
<meta charset="UTF-8" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="copyright" content="©" />
<meta name="robot" content="noindex, nofollow" />
<title>sample code</title>
</head>
</html>
采纳答案by Torsten Walter
There is no such thing as minimum meta tags (unless of course I got your question wrong). As far as I am aware no meta tag is required and the ones you add are the ones for your specific needs.
没有最小元标记这样的东西(当然,除非我把你的问题弄错了)。据我所知,不需要元标记,您添加的标记是满足您特定需求的标记。
Consider the following document:
考虑以下文档:
<!DOCTYPE HTML>
<html>
<head>
<title>Some Title</title>
</head>
<body>
</body>
</html>
You can validate it and not get any warning whatsoever. The validator just reminds you that the default encoding is missing. This is not even a warning, just an information.
您可以验证它并且不会收到任何警告。验证器只是提醒您缺少默认编码。这甚至不是警告,只是一个信息。
The working drafthas this to say about meta tags:
该工作草案有这样说的meta标签:
The meta element represents various kinds of metadata that cannot be expressed using the title, base, link, style, and script elements.
meta 元素表示无法使用标题、基础、链接、样式和脚本元素表示的各种元数据。
And it goes on:
它继续:
4.2.5.1 Standard metadata names
application-name, author, description, generator, keywords
4.2.5.1 标准元数据名称
应用程序名称、作者、描述、生成器、关键字
Further it mentions some additional tags concerning a page's status, contextual representation and character encoding.
此外,它还提到了一些关于页面状态、上下文表示和字符编码的附加标签。
Although none of these ar explicitly required by the standard, there are in fact best practices, especially concerning search engine optimization (SEO). This has nothing to do with the HTML standard but with web (search) crawlers.
尽管这些标准都没有明确要求,但实际上存在最佳实践,尤其是关于搜索引擎优化 (SEO) 的实践。这与 HTML 标准无关,而是与网络(搜索)爬虫有关。
You can get some good advice which meta tags matter (for Google) at the Webmaster Tools meta tag support page
您可以在网站管理员工具元标记支持页面上获得一些好的建议,哪些元标记很重要(对于 Google)
回答by Jukka K. Korpela
No meta
tag is required by any HTML5 draft. (HTML5 is work in progress and may change at any moment without prior notice.)
没有meta
标签被任何HTML5草案要求。(HTML5 正在开发中,可能随时更改,恕不另行通知。)
Many of the tags you list, including the one with content-language
, aren't even allowed (conforming) according to HTML5 drafts. In practice, most of them are useless, but some of them are actively harmful (such as the one that excludes robots, and in most cases those that try to prevent all caching).
content-language
根据 HTML5 草案,您列出的许多标签,包括带有 的标签,甚至都不允许(符合)。在实践中,它们中的大多数是无用的,但其中一些是积极有害的(例如排除机器人的那些,以及在大多数情况下试图阻止所有缓存的那些)。
Your latter fragment of code is invalid: the html
element must contain all other elements, and the head
element must contain a title
element (in all HTML versions).
您的后一段代码无效:该html
元素必须包含所有其他元素,并且该head
元素必须包含一个title
元素(在所有 HTML 版本中)。
Consult the newest W3C HTML5draft and use the experimental checker http://validator.nu.
查阅最新的W3C HTML5草案并使用实验检查器http://validator.nu。
回答by thepoofpoof
According to http://validator.w3.org/the following is an absolutely minimal example of a valid HTML5 document, literally everything else is optional.
根据http://validator.w3.org/,以下是有效 HTML5 文档的绝对最小示例,实际上其他所有内容都是可选的。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Valid HTML5 Document!</title>
</head>
</html>
So, you absolutely must have the charset meta tag defined, and everything else is a matter of accomplishing your goals (search engine related stuff, cache control, etc).
因此,您绝对必须定义字符集元标记,而其他一切都是实现您的目标(搜索引擎相关的内容、缓存控制等)的问题。