<dl>: The Description List element

<dl> HTML 元素表示描述列表。该元素包含术语组列表(使用 <dt> 元素指定)和描述(由 <dd> 元素提供)。此元素的常见用途是实现术语表或显示元数据(键值对列表)。

¥The <dl> HTML element represents a description list. The element encloses a list of groups of terms (specified using the <dt> element) and descriptions (provided by <dd> elements). Common uses for this element are to implement a glossary or to display metadata (a list of key-value pairs).

Try it

属性

¥Attributes

该元素仅包含 全局属性

¥This element only includes the global attributes.

示例

¥Examples

单一术语和描述

¥Single term and description

html
<dl>
  <dt>Firefox</dt>
  <dd>
    A free, open source, cross-platform, graphical web browser developed by the
    Mozilla Corporation and hundreds of volunteers.
  </dd>

  <!-- Other terms and descriptions -->
</dl>

结果

¥Result

多个术语,单一描述

¥Multiple terms, single description

html
<dl>
  <dt>Firefox</dt>
  <dt>Mozilla Firefox</dt>
  <dt>Fx</dt>
  <dd>
    A free, open source, cross-platform, graphical web browser developed by the
    Mozilla Corporation and hundreds of volunteers.
  </dd>

  <!-- Other terms and descriptions -->
</dl>

结果

¥Result

单个术语,多个描述

¥Single term, multiple descriptions

html
<dl>
  <dt>Firefox</dt>
  <dd>
    A free, open source, cross-platform, graphical web browser developed by the
    Mozilla Corporation and hundreds of volunteers.
  </dd>
  <dd>
    The Red Panda also known as the Lesser Panda, Wah, Bear Cat or Firefox, is a
    mostly herbivorous mammal, slightly larger than a domestic cat (60 cm long).
  </dd>

  <!-- Other terms and descriptions -->
</dl>

结果

¥Result

多个术语和描述

¥Multiple terms and descriptions

还可以通过组合以上示例来定义具有多个相应描述的多个术语。

¥It is also possible to define multiple terms with multiple corresponding descriptions, by combining the examples above.

元数据

¥Metadata

描述列表对于将元数据显示为键值对列表非常有用。

¥Description lists are useful for displaying metadata as a list of key-value pairs.

html
<dl>
  <dt>Name</dt>
  <dd>Godzilla</dd>
  <dt>Born</dt>
  <dd>1952</dd>
  <dt>Birthplace</dt>
  <dd>Japan</dd>
  <dt>Color</dt>
  <dd>Green</dd>
</dl>

结果

¥Result

提示:在 CSS 中定义键值分隔符会很方便,例如:

¥Tip: It can be handy to define a key-value separator in the CSS, such as:

css
dt::after {
  content: ": ";
}

将名称-值组封装在 div 元素中

¥Wrapping name-value groups in div elements

WHATWG HTML 允许将 <dl> 元素中的每个名称-值组封装在 <div> 元素中。当使用 microdata、或当 全局属性 应用于整个组或用于样式目的时,这可能很有用。

¥WHATWG HTML allows wrapping each name-value group in a <dl> element in a <div> element. This can be useful when using microdata, or when global attributes apply to a whole group, or for styling purposes.

html
<dl>
  <div>
    <dt>Name</dt>
    <dd>Godzilla</dd>
  </div>
  <div>
    <dt>Born</dt>
    <dd>1952</dd>
  </div>
  <div>
    <dt>Birthplace</dt>
    <dd>Japan</dd>
  </div>
  <div>
    <dt>Color</dt>
    <dd>Green</dd>
  </div>
</dl>

结果

¥Result

注意

¥Notes

请勿使用此元素(或 <ul> 元素)仅在页面上创建缩进。虽然它有效,但这是一种不好的做法,并且模糊了描述列表的含义。

¥Do not use this element (nor <ul> elements) to merely create indentation on a page. Although it works, this is a bad practice and obscures the meaning of description lists.

要更改描述术语的缩进,请使用 CSS margin 属性。

¥To change the indentation of a description term, use the CSS margin property.

无障碍问题

¥Accessibility concerns

每个屏幕阅读器以不同的方式显示 <dl> 内容,包括总数、术语/定义上下文和导航方法。这些差异不一定是错误。从 iOS 14 开始,当使用虚拟光标(而不是通过读取全部命令)导航时,VoiceOver 将宣布 <dl> 内容是一个列表。VoiceOver 不支持 <dl> 的列表导航命令。将 ARIA termdefinition 角色应用于 <dl> 结构时请小心,因为 VoiceOver(macOS 和 iOS)将调整它们的宣布方式。

¥Each screen reader exposes <dl> content differently, including total count, terms/definitions context, and navigation methods. These differences are not necessarily bugs. As of iOS 14, VoiceOver will announce that <dl> content is a list when navigating with the virtual cursor (not via the read-all command). VoiceOver does not support list navigation commands with <dl>. Be careful applying ARIA term and definition roles to <dl> constructs as VoiceOver (macOS and iOS) will adjust how they are announced.

技术总结

¥Technical summary

内容类别 流量内容,如果 <dl> 元素的子元素包含一个名称-值组,则可感知的内容。
允许的内容

任何一个:零个或多个基团,每个基团由一个或多个 <dt> 元素和后跟一个或多个 <dd> 元素组成,可选地与 <script><template> 元素混合。
或者:(在 WHATWG HTML、W3C HTML 5.2 及更高版本中)一个或多个 <div> 元素,可以选择与 <script><template> 元素混合。

标签遗漏 无,开始和结束标记都是强制性的。
允许的父级 任何接受 流动内容 的元素。
隐式 ARIA 角色 没有对应的角色
允许的 ARIA 角色 group, list, none, presentation
DOM 接口 HTMLDListElement

规范

Specification
HTML Standard
# the-dl-element

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also