HTML
<h1>
–
<h6>
元素
represent six levels of section headings.
<h1>
is the highest section level and
<h6>
is the lowest.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
| 内容类别 | 流内容 , heading content, palpable content. |
|---|---|
| 准许内容 | 措词内容 . |
| Tag omission | None, both the starting and ending tag are mandatory. |
| Permitted parents |
Any element that accepts
flow content
; don't use a heading element as a child of the
<hgroup>
element — it is now deprecated.
|
| Implicit ARIA role | heading |
| Permitted ARIA roles |
tab
,
presentation
or
none
|
| DOM 接口 |
HTMLHeadingElement
|
These elements only include the 全局属性 .
align
attribute is obsolete; don't use it.
font-size
特性。
<h1>
, followed by
<h2>
依此类推。
<h1>
per page or view. It should concisely describe the overall purpose of the content.
<h1>
will not result in an error, but is not considered a best practice. It is beneficial for screenreader users, and
SEO
.
<h1>
per
sectioning element
, it is not considered best practice, and may subvert the expectations of how screen reader users navigate.
The following code shows all the heading levels, in use.
<h1>Heading level 1</h1> <h2>Heading level 2</h2> <h3>Heading level 3</h3> <h4>Heading level 4</h4> <h5>Heading level 5</h5> <h6>Heading level 6</h6>
Here is the result of this code:
The following code shows a few headings with some content under them.
<h1>Heading elements</h1> <h2>Summary</h2> <p>Some text here...</p> <h2>Examples</h2> <h3>Example 1</h3> <p>Some text here...</p> <h3>Example 2</h3> <p>Some text here...</p> <h2>See also</h2> <p>Some text here...</p>
Here is the result of this code:
A common navigation technique for users of screen reading software is jumping from heading to heading to quickly determine the content of the page. Because of this, it is important to not skip one or more heading levels. Doing so may create confusion, as the person navigating this way may be left wondering where the missing heading is.
<h1>Heading level 1</h1> <h3>Heading level 3</h3> <h4>Heading level 4</h4>
<h1>Heading level 1</h1> <h2>Heading level 2</h2> <h3>Heading level 3</h3>
Headings may be nested as subsections to reflect the organization of the content of the page. Most screen readers can also generate an ordered list of all the headings on a page, which can help a person quickly determine the hierarchy of the content:
h1
Beetles
h2
Etymology
h2
Distribution and Diversity
h2
Evolution
h3
Late Paleozoic
h3
Jurassic
h3
Cretaceous
h3
Cenozoic
h2
External Morphology
h3
Head
h4
Mouthparts
h3
Thorax
h4
Prothorax
h4
Pterothorax
h3
Legs
h3
Wings
h3
Abdomen
When headings are nested, heading levels may be "skipped" when closing a subsection.
Another common navigation technique for users of screen reading software is to generate a list of 区间内容 and use it to determine the page's layout.
Sectioning content can be labeled using a combination of the
aria-labelledby
and
id
attributes, with the label concisely describing the purpose of the section. This technique is useful for situations where there is more than one sectioning element on the same page.
<header>
<nav aria-labelledby="primary-navigation">
<h2 id="primary-navigation">Primary navigation</h2>
<!-- navigation items -->
</nav>
</header>
<!-- page content -->
<footer>
<nav aria-labelledby="footer-navigation">
<h2 id="footer-navigation">Footer navigation</h2>
<!-- navigation items -->
</nav>
</footer>
In this example, screen reading technology would announce that there are two
<nav>
sections, one called "Primary navigation" and one called "Footer navigation". If labels were not provided, the person using screen reading software may have to investigate each
nav
element's contents to determine their purpose.
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | |
h1
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 4 | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
完整支持