<meta>:元数据元素

<meta> HTML 元素表示无法由其他 HTML 元相关元素(如 <base><link><script><style><title>)表示的 metadata

¥The <meta> HTML element represents metadata that cannot be represented by other HTML meta-related elements, like <base>, <link>, <script>, <style> or <title>.

<meta> 元素提供的元数据类型可以是以下之一:

¥The type of metadata provided by the <meta> element can be one of the following:

  • 如果设置了 name 属性,则 <meta> 元素提供文档级元数据,应用于整个页面。
  • 如果设置了 http-equiv 属性,则 <meta> 元素是一个 pragma 指令,提供与名称类似的 HTTP 标头所提供的信息等效的信息。
  • 如果设置了 charset 属性,则 <meta> 元素是字符集声明,给出文档编码所用的字符编码。
  • 如果设置了 itemprop 属性,则 <meta> 元素提供用户定义的元数据。

属性

¥Attributes

该元素包括 全局属性

¥This element includes the global attributes.

注意:属性 name 对于 <meta> 元素具有特定含义,并且不得在具有任何现有 namehttp-equivcharset 属性的同一 <meta> 元素上设置 itemprop 属性。

¥Note: the attribute name has a specific meaning for the <meta> element, and the itemprop attribute must not be set on the same <meta> element that has any existing name, http-equiv or charset attributes.

charset

该属性声明文档的字符编码。如果存在该属性,则其值必须是字符串 "utf-8" 的 ASCII 不区分大小写的匹配项,因为 UTF-8 是 HTML5 文档的唯一有效编码。声明字符编码的 <meta> 元素必须完全位于文档的前 1024 个字节内。

content

该属性包含 http-equivname 属性的值,具体取决于所使用的属性。

http-equiv

定义一个杂注指令。该属性被命名为 http-equiv(alent),因为所有允许的值都是特定 HTTP 标头的名称:

  • content-security-policy 允许页面作者为当前页面定义 内容政策。内容策略主要指定允许的服务器源和脚本端点,这有助于防范跨站点脚本攻击。
  • content-type 声明 MIME 类型 和文档的字符编码。如果指定,content 属性必须具有值 "text/html; charset=utf-8"。这相当于指定了 charset 属性的 <meta> 元素,并且对文档中的放置具有相同的限制。注意:只能在使用 text/html 提供的文档中使用,而不能在使用 XML MIME 类型提供的文档中使用。
  • default-style 设置默认 CSS 样式表 集的名称。
  • x-ua-compatible 如果指定,content 属性必须具有值 "IE=edge"。用户代理需要忽略此编译指示。
  • refresh 该指令规定:
    • 重新加载页面之前的秒数 - 仅当 content 属性包含非负整数时。
    • 页面应重定向到另一个页面之前的秒数 - 仅当 content 属性包含非负整数后跟字符串“;url=”和有效 URL 时。

    警告:

    ¥Warning:

    设置为 refresh 值的页面存在时间间隔太短的风险。借助屏幕阅读器等辅助技术进行导航的用户可能无法在自动重定向之前通读并理解页面内容。页面内容的突然、未经通知的更新也可能会让视力低下的人迷失方向。

    ¥Pages set with a refresh value run the risk of having the time interval being too short. People navigating with the aid of assistive technology such as a screen reader may be unable to read through and understand the page's content before being automatically redirected. The abrupt, unannounced updating of the page content may also be disorienting for people experiencing low vision conditions.

name

namecontent 属性可以一起使用,以名称-值对的形式提供文档元数据,其中 name 属性给出元数据名称,content 属性给出值。

有关 HTML 规范中定义的标准元数据名称集的详细信息,请参阅 标准元数据名称

示例

¥Examples

html
<meta charset="utf-8" />

<!-- Redirect page after 3 seconds -->
<meta http-equiv="refresh" content="3;url=https://www.mozilla.org" />

技术总结

¥Technical summary

内容类别 元数据内容.如果存在 itemprop 属性: 流动内容, 措辞内容
允许的内容 没有任何;这是 void element
标签遗漏 必须有开始标记,并且不能有结束标记。
允许的父级
隐式 ARIA 角色 没有对应的角色
允许的 ARIA 角色 不允许 role
DOM 接口 HTMLMetaElement

规范

Specification
HTML Standard
# the-meta-element

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看