<h1>–<h6>: The HTML Section Heading elements #
::: section-content
The <h1>
to <h6>
HTML elements represent six levels of
section headings. <h1>
is the highest section level and <h6>
is the
lowest. By default, all heading elements create a
block-level
box in the layout, starting on a new line and taking up the full width
available in their containing block.
:::
Try it #
::: section-content ::: iframe ::: {.output-header .border-rounded-top}
HTML Demo: <h1-h6> #
Reset :::
::: {#warning-no-script .warning-container} ::: warning The interactive example cannot be shown because JavaScript is disabled. ::: :::
::: {#warning-mathml-not-supported .warning-container .hidden} ::: warning The interactive example cannot be shown because MathML is not supported by your browser. ::: :::
::: {#editor-container .editor-container .tabbed-standard .hidden .border-rounded-bottom editor-type=“tabbed”} ::: {#tab-container .section .tabs} ::: {#tablist .tab-list role=“tablist”} HTML
CSS
JavaScript :::
::: {#html-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“html” aria-hidden=“true”} ::: {#html-editor}
Beetles
External morphology
Head
Mouthparts
Thorax
Prothorax
Pterothorax
::: :::::: {#css-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“css” aria-hidden=“true”} ::: {#css-editor} h1, h2, h3, h4 { margin: 0.1rem 0; }
h1 {
font-size: 2rem;
}
h2 {
font-size: 1.5rem;
padding-left: 20px;
}
h3 {
font-size: 1.2rem;
padding-left: 40px;
}
h4 {
font-size: 1rem;
font-style: italic;
padding-left: 60px;
}
::: :::
::: {#js-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“js” aria-hidden=“true”} ::: {#js-editor} ::: ::: :::
::: {#output .output-container}
Output #
::: :::
::: {.section .console-container .hidden aria-hidden=“true”}
Console Output #
![] clear console
::: {#console .console} ::: :::
::: {#html-output .output .editor-tabbed} %html-content% ::: :::
Content categories | Flow content, heading content, palpable content. |
---|---|
Permitted content | Phrasing content. |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parents | Any element that accepts flow content. |
Implicit ARIA role | heading |
Permitted ARIA roles | tab ,
presentation
or none |
DOM interface | HTMLHeadingElement |
Attributes #
::: section-content These elements only include the global attributes. :::
Usage notes #
::: section-content
- Heading information can be used by user agents to construct a table of contents for a document automatically.
- Do not use heading elements to resize text. Instead, use the
CSS
font-size
property. - Do not skip heading levels: always start from
<h1>
, followed by<h2>
and so on. :::
Avoid using multiple <h1>
elements on one page
#
::: section-content
While using multiple <h1>
elements on one page is allowed by the HTML
standard (as long as they are not
nested), this is not
considered a best practice. A page should generally have a single <h1>
element that describes the content of the page (similar to the
document's
<title> element
).
::: {#sect1 .notecard .note}
Note: Nesting multiple <h1>
elements in nested
sectioning
elements was allowed in older versions
of the HTML standard. However, this was never considered a best practice
and is now non-conforming. Read more in
There Is No Document Outline
Algorithm{target="_blank"}.
:::
Prefer using only one <h1>
per page and
nest headings
without skipping levels.
:::
Examples #
All headings #
::: section-content The following code shows all the heading levels, in use.
::: code-example [html]{.language-name}
<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>
:::
::: {#sect2 .code-example} ::: iframe ::: ::: :::
Example page #
::: section-content The following code shows a few headings with some content under them.
::: code-example [html]{.language-name}
<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>
:::
::: {#sect3 .code-example} ::: iframe ::: ::: :::
Accessibility concerns #
Navigation #
::: section-content A common navigation technique for users of screen reading software is to quickly jump from heading to heading in order to 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.
Don't do this:
::: code-example [html]{.language-name}
<h1>Heading level 1</h1>
<h3>Heading level 3</h3>
<h4>Heading level 4</h4>
:::
Prefer this:
::: code-example [html]{.language-name}
<h1>Heading level 1</h1>
<h2>Heading level 2</h2>
<h3>Heading level 3</h3>
:::
Nesting #
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
Beetlesh2
Etymologyh2
Distribution and Diversityh2
Evolutionh3
Late Paleozoich3
Jurassich3
Cretaceoush3
Cenozoic
h2
External Morphologyh3
Headh4
Mouthparts
h3
Thoraxh4
Prothoraxh4
Pterothorax
h3
Legsh3
Wingsh3
Abdomen
When headings are nested, heading levels may be "skipped" when closing a subsection.
- Headings • Page Structure • WAI Web Accessibility Tutorials{target="_blank"}
- MDN Understanding WCAG, Guideline 1.3 explanations
- Understanding Success Criterion 1.3.1 | W3C Understanding WCAG 2.0{target="_blank"}
- MDN Understanding WCAG, Guideline 2.4 explanations
- Understanding Success Criterion 2.4.1 | W3C Understanding WCAG 2.0{target="_blank"}
- Understanding Success Criterion 2.4.6 | W3C Understanding WCAG 2.0{target="_blank"}
- Understanding Success Criterion 2.4.10 | W3C Understanding WCAG 2.0{target="_blank"} :::
Labeling section content #
::: section-content Another common navigation technique for users of screen reading software is to generate a list of sectioning content 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.
Sectioning content examples #
::: code-example [html]{.language-name}
<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>
:::
::: {#sect4 .code-example} ::: iframe ::: :::
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.
- Using the aria-labelledby attribute
- Labeling Regions • Page Structure • W3C WAI Web Accessibility Tutorials{target="_blank"} :::
Specifications #
::: _table #
Specification #
HTML Standard
[#
the-h1,-h2,-h3,-h4,-h5,-and-h6-elements]{.small}
:::
Browser compatibility #
::: _table Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
Heading_Elements
1 12 1 Yes 15 ≤4 4.4 18 4 14 ≤3.2 1.0
:::
See also #
::: section-content
::: _attribution
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5
or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements{._attribution-link}
:::