本文为HTML标准解读系列文章,其他文章详见这里。
在HTML中,有一类标签,虽然很重要,但由于大部分不会被浏览器渲染出来,而被很多开发者所忽略,这类标签叫作元数据内容标签。
如果你不知道什么是叫「元数据」,可以看看维基百科对元数据的定义:
Metadata is “data that provides information about other data”。
元数据是“给其他数据提供信息的数据”。
如果范围缩小到HTML上,HTML标准对于「元数据内容」的定义是这样的:
Metadata content is content that sets up the presentation or behavior of the rest of the content, or that sets up the relationship of the document with other documents, or that conveys other “out of band” information.
元数据内容是具有如下作用的内容:设置整体内容的呈现或者行为、设置本文档与其他文档之间的关系、传达其他主内容以外的信息。
对于这个定义,可以举几个例子:
<!-- 设置整体内容的呈现:设置默认背景夜色为dark -->
<meta name="color-scheme" content="dark">
<!-- 设置整体文档的行为:每30秒刷新页面 -->
<meta http-equiv="refresh" content="30">
<!-- 设置本文档与其他文档之间的关系:设置本文档的作者页 -->
<link rel="author" href="./author.html">
<!-- 传达其他主内容以外的信息: 设置文档title -->