<hgroup>: 標題分組元素

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

<hgroup> HTML 元素代表一個標題及其相關內容。它將單個 <h1>–<h6> 元素與一個或多個 <p> 元素分組。

試一試

<hgroup>
  <h1>Frankenstein</h1>
  <p>Or: The Modern Prometheus</p>
</hgroup>
<p>
  Victor Frankenstein, a Swiss scientist, has a great ambition: to create
  intelligent life. But when his creature first stirs, he realizes he has made a
  monster. A monster which, abandoned by his master and shunned by everyone who
  sees it, follows Dr Frankenstein to the very ends of the earth.
</p>
hgroup {
  text-align: right;
  padding-right: 16px;
  border-right: 10px solid #00c8d7;
}

hgroup h1 {
  margin-bottom: 0;
}

hgroup p {
  margin: 0;
  font-weight: bold;
}

屬性

此元素僅包含全域性屬性

用法說明

<hgroup> 元素允許將標題與任何輔助內容分組,例如副標題、替代標題或標語。這些型別的內容中的每一種都表示為 <hgroup> 中的 <p> 元素。

<hgroup> 本身對網頁的文件大綱沒有影響。相反,<hgroup> 中允許的單個標題會影響文件大綱。

示例

html
<!doctype html>
<title>HTML Standard</title>
<body>
  <hgroup id="document-title">
    <h1>HTML: Living Standard</h1>
    <p>Last Updated 12 July 2022</p>
  </hgroup>
  <p>Some intro to the document.</p>
  <h2>Table of contents</h2>
  <ol id="toc">
    …
  </ol>
  <h2>First section</h2>
  <p>Some intro to the first section.</p>
</body>

結果

技術摘要

內容類別 流內容、標題內容、可感知內容。
允許內容 零個或多個 <p> 元素,後跟一個 h1h2h3h4h5h6 元素,後跟零個或多個 <p> 元素。
標籤省略 無,起始標籤和結束標籤都必須存在。
允許父級 任何接受流內容的元素。
隱式 ARIA 角色 group
允許的 ARIA 角色 任意
DOM 介面 HTMLElement

規範

規範
HTML
# the-hgroup-element

瀏覽器相容性

另見