内容类别

大多数 HTML 元素都是一个或多个内容类别的成员 - 这些类别对具有共同特性的元素进行分组。这是一个松散的分组(它实际上并不在这些类别的元素之间创建关系),但它们有助于定义和描述类别的共享行为及其相关规则,特别是当你遇到它们复杂的细节时。元素也有可能不属于这些类别中的任何一个。

¥Most HTML elements are a member of one or more content categories — these categories group elements that share common characteristics. This is a loose grouping (it doesn't actually create a relationship among elements of these categories), but they help define and describe the categories' shared behavior and their associated rules, especially when you come upon their intricate details. It's also possible for elements to not be a member of any of these categories.

内容类别分为三种类型:

¥There are three types of content categories:

  • 主要内容类别,描述许多元素共享的通用规则。
  • 表单相关内容类别,描述表单相关元素通用的规则。
  • 特定内容类别,描述仅由少数元素共享的罕见类别,有时仅在特定上下文中。

注意:对这些内容类别及其比较功能的更详细讨论超出了本文的范围;为此,你可能希望阅读 HTML 规范的相关部分

¥Note: A more detailed discussion of these content categories and their comparative functionalities is beyond the scope of this article; for that, you may wish to read the relevant portions of the HTML specification.

A Venn diagram showing how the various content categories interrelate. The following sections explain these relationships in text.

主要内容类别

¥Main content categories

元数据内容

¥Metadata content

属于元数据内容类别的元素修改文档其余部分的表示或行为、设置到其他文档的链接或传达其他带外信息。

¥Elements belonging to the metadata content category modify the presentation or the behavior of the rest of the document, set up links to other documents, or convey other out-of-band information.

属于该类别的元素有 <base><link><meta><noscript><script><style><title>

¥Elements belonging to this category are <base>, <link>, <meta>, <noscript>, <script>, <style> and <title>.

流量内容

¥Flow content

流内容是一个广泛的类别,包含可以放入 <body> 元素内部的大多数元素,包括标题元素、分段元素、短语元素、嵌入元素、交互元素和表单相关元素。它还包括文本节点(但不包括仅由空白字符组成的文本节点)。

¥Flow content is a broad category that encompasses most elements that can go inside the <body> element, including heading elements, sectioning elements, phrasing elements, embedding elements, interactive elements, and form-related elements. It also includes text nodes (but not those that only consist of white space characters).

流程要素是:

¥The flow elements are:

其他一些元素也属于此类别,但前提是满足特定条件:

¥A few other elements belong to this category, but only if a specific condition is fulfilled:

切片内容

¥Sectioning content

分段内容是流内容的子集,它创建定义 <header><footer> 元素范围的 当前大纲中的部分

¥Sectioning content, a subset of flow content, creates a section in the current outline defining the scope of <header> and <footer> elements.

属于该类别的元素有 <article><aside><nav><section>

¥Elements belonging to this category are <article>, <aside>, <nav>, and <section>.

标题内容

¥Heading content

标题内容是流内容的子集,定义部分的标题。此定义既适用于由显式 分段内容 元素标记的部分,也适用于由标题内容本身隐式定义的部分。

¥Heading content, a subset of flow content, defines the title of a section. This definition applies both to sections marked by an explicit sectioning content elements and to those implicitly defined by the heading content itself.

属于该类别的元素是 SS1-SS2<hgroup>

¥Elements belonging to this category are <code><h1>-<h6> and <hgroup>.

注意:尽管可能包含标题内容,但 <header> 本身并不是标题内容。

¥Note: Though likely to contain heading content, the <header> is not heading content itself.

措辞内容

¥Phrasing content

短语内容是流内容的子集,是指文档中的文本和标记。措辞内容的序列构成段落。

¥Phrasing content, a subset of flow content, refers to the text and the markup within a document. Sequences of phrasing content make up paragraphs.

属于该类别的元素有:

¥Elements belonging to this category are:

其他一些元素也属于此类别,但前提是满足特定条件:

¥A few other elements belong to this category, but only if a specific condition is fulfilled:

嵌入内容

¥Embedded content

嵌入内容是流内容的子集,可导入其他资源或将其他标记语言或命名空间中的内容插入到文档中。属于此类别的元素包括:

¥Embedded content, a subset of flow content, imports another resource or inserts content from another markup language or namespace into the document. Elements that belong to this category include:

互动内容

¥Interactive content

交互式内容是流内容的子集,包括专门为用户交互设计的元素。属于此类别的元素包括:

¥Interactive content, a subset of flow content, includes elements that are specifically designed for user interaction. Elements that belong to this category include:

有些元素仅在特定条件下才属于此类别:

¥Some elements belong to this category only under specific conditions:

触手可及的内容

¥Palpable content

当内容既不空洞也不隐藏时,它就是显而易见的;它是呈现的内容并且是实质性的。以流内容为模型的元素应该至少有一个可触及的节点。

¥Content is palpable when it's neither empty nor hidden; it is content that is rendered and is substantive. Elements whose model is flow content should have at least one node which is palpable.

表单相关内容

¥Form-associated content

表单关联内容是流内容的子集,其中包含具有表单所有者、由表单属性公开的元素,并且可以在需要流内容的任何地方使用。表单所有者是包含 <form> 的元素或其 id 在表单属性中指定的元素。

¥Form-associated content is a subset of flow content comprising elements that have a form owner, exposed by a form attribute, and can be used everywhere flow content is expected. A form owner is either the containing <form> element or the element whose id is specified in the form attribute.

该类别包含多个子类别:

¥This category contains several sub-categories:

listed

form.elementsfieldset.elements 集合中列出的元素。包含 <button><fieldset><input><object><output><select><textarea>

labelable

可以与 <label> 元素关联的元素。包含 <button><input><meter><output><progress><select><textarea>

submittable

提交表单时可用于构造表单数据集的元素。包含 <button><input><object><select><textarea>

resettable

重置表单时可能受影响的元素。包含 <input><output><select><textarea>

次要内容类别

¥Secondary content categories

元素的一些二级分类也值得了解。

¥There are some secondary classifications of elements that can be useful to be aware of as well.

脚本支持元素

¥Script-supporting elements

支持脚本的元素是不直接影响文档的呈现输出的元素。相反,它们通过直接包含或指定脚本代码,或者通过指定脚本将使用的数据来支持脚本。

¥Script-supporting elements are elements which don't directly contribute to the rendered output of a document. Instead, they serve to support scripts, either by containing or specifying script code directly, or by specifying data that will be used by scripts.

脚本支持元素是:

¥The script-supporting elements are:

透明内容模型

¥Transparent content model

如果元素具有透明内容模型,则其内容的结构必须使其成为有效的 HTML 5,即使透明元素被删除并由子元素替换也是如此。

¥If an element has a transparent content model, then its contents must be structured such that they would be valid HTML 5, even if the transparent element were removed and replaced by the child elements.

例如,<del><ins> 元素是透明的:

¥For example, the <del> and <ins> elements are transparent:

html
<p>
  We hold these truths to be <del><em>sacred &amp; undeniable</em></del>
  <ins>self-evident</ins>.
</p>

如果这些元素被删除,这个片段仍然是有效的 HTML(如果不是正确的英语)。

¥If those elements were removed, this fragment would still be valid HTML (if not correct English).

html
<p>We hold these truths to be <em>sacred &amp; undeniable</em> self-evident.</p>