标准元数据名称

<meta> 元素可用于以名称-值对的形式提供文档元数据,其中 name 属性给出元数据名称,content 属性给出值。

¥The <meta> element can be used to provide document metadata in terms of name-value pairs, with the name attribute giving the metadata name, and the content attribute giving the value.

HTML 规范中定义的标准元数据名称

¥Standard metadata names defined in the HTML specification

HTML 规范定义了以下一组标准元数据名称:

¥The HTML specification defines the following set of standard metadata names:

  • application-name:网页中运行的应用的名称。

    注意:

    ¥Note:

    • 浏览器可以使用它来识别应用。它与 <title> 元素不同,后者通常包含应用名称,但也可能包含文档名称或状态等信息。
    • 简单的网页不应定义应用名称。
  • author:文档作者的名称。
  • description:页面内容的简短而准确的摘要。一些浏览器,如 Firefox 和 Opera,使用它作为书签页面的默认描述。
  • generator:生成页面的软件的标识符。
  • keywords:与页面内容相关的单词,以逗号分隔。
  • referrer:控制从文档发送的请求的 HTTP Referer 标头:
    Values for the content attribute of <meta name="referrer">
    no-referrer 不要发送 HTTP Referer 标头。
    origin 发送文档的 origin
    no-referrer-when-downgrade 当目标至少与当前页面一样安全时(HTTP(S)→HTTPS)发送完整 URL,但当安全性较低时(HTTPS→HTTP)不发送引荐来源网址。这是默认行为。
    origin-when-cross-origin 对于同源请求,发送完整的 URL(去除参数),但对于其他情况,仅发送源。
    same-origin 发送同源请求的完整 URL(去除参数)。跨源请求将不包含引用标头。
    strict-origin 当目标至少与当前页面一样安全时发送源(HTTP(S)→HTTPS),但当安全性较低时(HTTPS→HTTP)不发送引荐来源网址。
    strict-origin-when-cross-origin 发送同源请求的完整 URL(去除参数)。当目标至少与当前页面一样安全时发送源(HTTP(S)→HTTPS)。否则,不发送推荐人。
    unsafe-URL 发送同源或跨源请求的完整 URL(去除参数)。

    注意:

    ¥Note:

    • 动态插入 <meta name="referrer">(与 document.write()appendChild())会使引荐来源网址行为变得不可预测。
    • 当定义了多个冲突的策略时,将应用 no-referrer 策略。
  • theme-color:指示用户代理应该用来自定义页面或周围用户界面的显示的建议颜色。content 属性包含有效的 CSS 。可以包含具有有效媒体查询列表的 media 属性来设置主题颜色元数据应用到的媒体。
  • color-scheme:指定文档兼容的一种或多种配色方案。 浏览器将使用此信息与用户的浏览器或设备设置一起确定从背景和前景到形成控件和滚动条的所有内容使用什么颜色。<meta name="color-scheme"> 的主要用途是指示浅色和夜间模式的兼容性以及优先顺序。 color-schemecontent 属性值可以是以下之一:
    normal

    该文档不知道配色方案,应使用默认调色板进行渲染。

    [light | dark]+

    文档支持的一种或多种配色方案。多次指定相同的配色方案与仅指定一次具有相同的效果。指示多种颜色方案表示文档首选第一个方案,但如果用户喜欢,则可以接受第二个指定的方案。

    only light

    表示文档仅支持浅色模式,背景颜色为浅色,前景色为深色。根据规范,only dark 无效,因为当文档不真正兼容时强制文档以夜间模式呈现可能会导致内容不可读;如果没有另外配置,所有主要浏览器都默认为轻型模式。

    例如,指示文档更喜欢夜间模式,但在浅色模式下也能正常渲染:
    html
    <meta name="color-scheme" content="dark light" />
    
    这在文档级别的工作方式与 CSS color-scheme 属性允许各个元素指定其首选和接受的配色方案相同。你的样式可以使用 prefers-color-scheme CSS 媒体功能适应当前的配色方案。

其他规范中定义的标准元数据名称

¥Standard metadata names defined in other specifications

CSS 设备适配规范定义了以下元数据名称:

¥The CSS Device Adaptation specification defines the following metadata name:

  • viewport:给出了有关 viewport 初始大小的提示。
    Values for the content of <meta name="viewport">
    可能的子值 描述
    width A positive integer number, or the text device-width 定义你希望渲染网站的视口的像素宽度。
    height A positive integer, or the text device-height 定义视口的高度。不被任何浏览器使用。
    initial-scale A positive number between 0.0 and 10.0 Defines the ratio between the device width (device-width in portrait mode or device-height in landscape mode) and the viewport size.
    maximum-scale A positive number between 0.0 and 10.0 Defines the maximum amount to zoom in. It must be greater or equal to the minimum-scale or the behavior is undefined. Browser settings can ignore this rule and iOS10+ ignores it by default.
    minimum-scale A positive number between 0.0 and 10.0 Defines the minimum zoom level. It must be smaller or equal to the maximum-scale or the behavior is undefined. Browser settings can ignore this rule and iOS10+ ignores it by default.
    user-scalable yes or no If set to no, the user is not able to zoom in the webpage. The default is yes. Browser settings can ignore this rule, and iOS10+ ignores it by default.
    viewport-fit auto, contain or cover

    The auto value doesn't affect the initial layout viewport, and the whole web page is viewable.

    The contain value means that the viewport is scaled to fit the largest rectangle inscribed within the display.

    The cover value means that the viewport is scaled to fill the device display. It is highly recommended to make use of the safe area inset variables to ensure that important content doesn't end up outside the display.

    警告:

    ¥Warning:

    通过将 user-scalable 设置为 no 的值来禁用缩放功能可防止视力不佳的人阅读和理解页面内容。

    ¥Disabling zooming capabilities by setting user-scalable to a value of no prevents people experiencing low vision conditions from being able to read and understand page content.

其他元数据名称

¥Other metadata names

WHATWG Wiki MetaExtensions 页面 包含大量尚未正式接受的非标准元数据名称;然而,其中包含的一些名称在实践中已经非常常用 - 包括以下名称:

¥The WHATWG Wiki MetaExtensions page contains a large set of non-standard metadata names that have not been formally accepted yet; however, some of the names included there are already used quite commonly in practice — including the following:

  • creator:文档创建者的名称,例如组织或机构。如果有多个,则应使用多个 <meta> 元素。
  • googlebotrobots 的同义词,后面只有 Googlebot(Google 的索引爬虫)。
  • publisher:文档发布者的名称。
  • robots:协作爬虫(或 "robots")应与页面一起使用的行为。它是以下值的逗号分隔列表:
    描述 使用者
    index 允许机器人索引页面(默认)。 全部
    noindex 请求机器人不要索引该页面。 全部
    follow 允许机器人跟踪页面上的链接(默认)。 全部
    nofollow 请求机器人不要点击页面上的链接。 全部
    all 相当于 index, follow 谷歌
    none 相当于 noindex, nofollow 谷歌
    noarchive 请求搜索引擎不要缓存页面内容。 谷歌, 雅虎, 必应
    nosnippet 防止在搜索引擎结果中显示页面的任何描述。 谷歌必应
    noimageindex 请求此页面不显示为索引图片的引用页面。 谷歌
    nocache noarchive 的同义词。 必应

    注意:

    ¥Note:

    • 只有协作机器人才会遵守这些规则。不要指望用它们来阻止电子邮件收集器。
    • 机器人仍然需要访问该页面才能阅读这些规则。为了防止带宽消耗,请考虑使用 robots.txt 文件是否更合适。
    • robots <meta> 标签和 robots.txt 文件有不同的用途:robots.txt 控制页面的抓取,并且不影响索引或 robots 元控制的其他行为。如果另一个文档引用了无法爬网的页面,则该页面仍可能被编入索引。
    • 如果你想删除一个页面,noindex 就可以工作,但前提是机器人再次访问该页面。确保 robots.txt 文件不会阻止重新访问。
    • 有些值是互斥的,例如 indexnoindex,或 follownofollow。在这些情况下,机器人的行为是不确定的,并且可能会有所不同。
    • 一些爬虫机器人,如 Google、Yahoo 和 Bing,支持相同的 HTTP 标头 X-Robots-Tag 值;这允许非 HTML 文档(例如图片)使用这些规则。

规范

Specification
HTML Standard
# standard-metadata-names
Referrer Policy
# referrer-policy-delivery-meta

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看