# meta元素

**meta元素**（`<meta>`）是一种HTML元素，用于表示无法由其他与meta相关的元素（如`<base>`、`<link>`、`<script>`、`<style>`或`<title>`）表示的文档级元数据。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup>它是一种空元素，没有内容，其信息完全承载于属性之中，定义在由WHATWG维护的HTML标准第4.2.5节。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup><sup> • </sup><sup>[2](https://html.spec.whatwg.org/print.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 元素类型 | 空元素：必须有起始标签，不得有结束标签，且不允许有内容<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup> |
| 四种模式 | `name`（文档元数据）、`http-equiv`（pragma指令）、`charset`（编码声明）、`itemprop`（用户自定义元数据）<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup> |
| 字符集规则 | `charset`值必须是`"utf-8"`的ASCII大小写不敏感匹配，且该元素必须完全位于文档的前1024个字节之内<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup> |
| 搜索控制 | robots `meta`标签按页面控制索引和呈现；`noindex`使页面不出现在Google搜索结果中<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup><sup> • </sup><sup>[4](https://developers.google.com/search/docs/crawling-indexing/control-what-you-share)</sup> |
| robots meta的起源 | 由Web标准社区于1996年开发，即在`meta`标签被提议加入HTML几个月之后<sup>[5](https://developers.google.com/search/blog/2025/03/robots-refresher-page-level)</sup> |
| 非HTML资源 | PDF、视频和图像的索引规则改为通过`X-Robots-Tag` HTTP响应头传递<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup> |
| 已废弃的用法 | `Set-Cookie`和`x-ua-compatible` pragma指令现已被浏览器忽略<sup>[6](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/http-equiv)</sup> |

## 元素的工作方式

一个`<meta>`元素只以四种模式之一运作，由所存在的属性决定。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup>

- 带有`name`属性时，该元素以名称-值对的形式提供文档级元数据，由`content`持有值。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup>
- 带有`http-equiv`属性时，该元素充当pragma指令，模拟原本可由HTTP头传递的指令；该属性名是“http-equivalent”（HTTP等价）的缩写。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup>
- 带有`charset`属性时，该元素声明文档的字符编码。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup>
- 带有`itemprop`属性时，该元素提供用户自定义元数据。`itemprop`属性不得设置在同时具有`name`、`http-equiv`或`charset`的`<meta>`元素上。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup>

位置对解析器很重要。`<meta charset>`和编码声明类的`<meta http-equiv>`元素应放在`<head>`元素中，且字符编码声明必须完全序列化在文档的前1024个字节之内；一个文档只能包含一个基于`meta`的编码声明。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup><sup> • </sup><sup>[7](https://html.spec.whatwg.org/dev/semantics.html)</sup>Google还警告说，如果`<head>`内出现无效元素，它会假定头部已结束并忽略其后的所有元素，因此位置错误的标记可能悄无声息地丢弃元数据。<sup>[8](https://developers.google.com/search/docs/crawling-indexing/valid-page-metadata)</sup>

## 标准元数据名称

HTML规范定义了一组标准`name`值，WHATWG Wiki的MetaExtensions页面则充当注册表，任何人都可以添加新的元数据名称。<sup>[9](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name)</sup><sup> • </sup><sup>[7](https://html.spec.whatwg.org/dev/semantics.html)</sup>标准名称包括：

- `description`，对页面的简短而准确的摘要，常被称为“meta description”；搜索引擎用它来调整页面在结果中的显示方式。<sup>[9](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name)</sup>
- `application-name`、`author`、`generator`和`keywords`，其中最后一个被搜索引擎忽略，因为垃圾信息发送者用数百个词条填充关键词列表，使结果产生偏差。<sup>[9](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name)</sup><sup> • </sup><sup>[10](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Structuring_content/Webpage_metadata)</sup>
- `color-scheme`，指示浅色和深色色彩模式的兼容性及偏好顺序；例如`content="light dark"`表示文档偏好浅色模式但支持深色。<sup>[11](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name/color-scheme)</sup>
- `theme-color`，建议一个颜色（以CSS `<color>`值给出），用户代理应使用该颜色来自定义页面或周围界面的显示；可选的`media`属性将颜色限定到某个媒体查询。<sup>[12](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name/theme-color)</sup>
- `viewport`，给出关于移动设备上视口应如何确定尺寸的提示。<sup>[13](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name/viewport)</sup>

viewport值之所以存在，是因为移动浏览器历史上以约980px的虚拟视口渲染页面；没有该声明，在640px或480px触发的媒体查询将永远不会生效，从而限制响应式设计。推荐的设置是`<meta name="viewport" content="width=device-width">`，它使视口与设备宽度匹配。<sup>[13](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name/viewport)</sup>

## 带http-equiv的pragma指令

`http-equiv`属性让作者提供处理指令，如同服务器发送了某些HTTP头。其定义的值包括`content-security-policy`，为页面设置内容安全策略，通常用于防范跨站脚本攻击；`default-style`，指定默认的CSS样式表集；以及`refresh`，在若干秒后重新加载页面或重定向到另一个URL，写法为`content="3;url=https://example.com"`。<sup>[6](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/http-equiv)</sup>HTTP的`Refresh`响应头与`<meta http-equiv="refresh">`形式完全等价。<sup>[14](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Refresh)</sup>

有两种曾经的用法已不再使用。`Set-Cookie` pragma指令曾为文档设置cookie，现已被浏览器忽略，转而使用`Set-Cookie` HTTP响应头或`document.cookie`；`x-ua-compatible`曾被已退役的Microsoft Internet Explorer旧版本使用，同样被用户代理忽略。<sup>[6](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/http-equiv)</sup>MDN还告诫不要通过`<meta http-equiv>`设置其他安全头，因为无法识别的头或无效值会被静默忽略，这可能造成虚假的安全感。<sup>[6](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/http-equiv)</sup>

## robots meta标签与搜索引擎

实践中最为人熟知的`name`值是`robots`。robots `meta`标签为站点所有者提供了一种细粒度的、针对具体页面的方式，来控制单个HTML页面在搜索结果中的索引和呈现方式，使用`noindex`、`nofollow`、`nosnippet`、`max-snippet:[number]`和`unavailable_after: [date/time]`等规则，可以以逗号分隔列表的形式组合使用。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup>`noindex`规则告诉Google不要索引该内容或在搜索结果中显示它，不过该页面仍可被链接和直接访问。<sup>[4](https://developers.google.com/search/docs/crawling-indexing/control-what-you-share)</sup>

若干实际约束影响着这些规则的运作方式：

- 爬虫只有在被允许访问页面的情况下才能遵循这些规则。被robots.txt禁止的URL如果从网络上其他地方被链接，仍可能被索引，因此要可靠地将页面排除在结果之外，Google建议使用密码保护、`noindex` meta标签或响应头，或者移除该页面。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup><sup> • </sup><sup>[15](https://developers.google.com/search/docs/crawling-indexing/robots/intro?authuser=117&hl=en)</sup>
- 当规则冲突时，适用限制更严格的规则；当针对多个爬虫设置了不同规则时，搜索引擎会应用所有负面规则的总和。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup>
- Google在该标签中支持两个用户代理令牌：`googlebot`用于所有文本结果，`googlebot-news`用于新闻结果；其他值会被忽略。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup>
- PDF、视频和图像文件等非HTML资源无法携带meta标签，因此其规则通过`X-Robots-Tag` HTTP响应头发送，该头接受相同的规则，并可在Apache或NGINX配置中全局设置。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup>
- 一个文本层面的配套手段是`span`、`div`和`section`元素上的`data-nosnippet`布尔属性，它将页面的某些部分排除在摘要之外。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup>

有些规则随着功能的消失而失效：`noarchive`不再使用，因为Google的缓存链接功能已不存在；`nositelinkssearchbox`也不再使用，因为站点链接搜索框已被移除。<sup>[3](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)</sup>

## meta refresh的可访问性

延迟的`meta refresh`与Web内容可访问性指南相互作用。W3C技术H76允许在作者无法实现服务器端重定向的情况下，使用`http-equiv="refresh"`且`content`值为`0`后跟目标URI来实现即时客户端重定向。<sup>[16](https://www.w3.org/WAI/WCAG22/Techniques/html/H76)</sup>相应的ACT规则检查任何刷新延迟是否落在0到72000秒（20小时）之间；零秒刷新算作重定向而豁免，更长的延迟则不符合WCAG成功标准2.2.1“时序可调”、2.2.4“中断”和3.2.5“应请求变更”。<sup>[17](https://www.w3.org/WAI/standards-guidelines/act/rules/bc659a/)</sup>MDN指出，较短的刷新间隔可能使屏幕阅读器用户来不及读完页面就被无预告地重定向。<sup>[6](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/http-equiv)</sup>

## 历史

robots `meta`标签由参与Web标准的社区于1996年开发，即在`meta`标签被提议加入HTML几个月之后，并且据轶闻，早于Google的创立。<sup>[5](https://developers.google.com/search/blog/2025/03/robots-refresher-page-level)</sup>该元素本身现已在WHATWG HTML Living Standard中规定，其核心功能自2015年7月起已在各浏览器中广泛可用，不过各个`name`值的支持程度不一；例如`theme-color`尚未达到Baseline，因为它在一些广泛使用的浏览器中不起作用。<sup>[1](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)</sup><sup> • </sup><sup>[12](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name/theme-color)</sup>

## References

1. [`<meta>` HTML metadata element, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta)
2. [HTML Standard, section 4.2.5 The meta element, WHATWG](https://html.spec.whatwg.org/print.pdf)
3. [Robots Meta Tags Specifications, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag)
4. [Control the Content You Share on Search, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/control-what-you-share)
5. [Robots Refresher: page-level granularity, Google Search Central Blog](https://developers.google.com/search/blog/2025/03/robots-refresher-page-level)
6. [`<meta http-equiv>` HTML attribute, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/http-equiv)
7. [HTML Standard, Edition for Web Developers (semantics), WHATWG](https://html.spec.whatwg.org/dev/semantics.html)
8. [Valid Page Metadata for Google Search, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/valid-page-metadata)
9. [`<meta name>` HTML attribute, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name)
10. [What's in the head? Web page metadata, MDN Learn](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Structuring_content/Webpage_metadata)
11. [`<meta name="color-scheme">` HTML attribute value, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name/color-scheme)
12. [`<meta name="theme-color">` HTML attribute value, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name/theme-color)
13. [`<meta name="viewport">` HTML attribute value, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name/viewport)
14. [Refresh header, HTTP, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Refresh)
15. [Robots.txt Introduction and Guide, Google Search Central](https://developers.google.com/search/docs/crawling-indexing/robots/intro?authuser=117&hl=en)
16. [H76: Using meta refresh to create an instant client-side redirect, W3C WAI](https://www.w3.org/WAI/WCAG22/Techniques/html/H76)
17. [Meta element has no refresh delay, ACT Rule, W3C WAI](https://www.w3.org/WAI/standards-guidelines/act/rules/bc659a/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Web development and web-platform technologies

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/meta-element

English original: https://www.edgepedia.org/meta-element
