–: The HTML Section Heading Elements - MDN - Mozilla
: The HTML Section Heading Elements - MDN - Mozilla
- References
- HTML
- Elements
- <h1>
- English (US)
- Remember language
- Deutsch
- Español
- Français
- 日本語
- 한국어
- Português (do Brasil)
- Русский
- 中文 (简体)
- 正體中文 (繁體)
- Try it
- Attributes
- Usage notes
- Accessibility
- Examples
- Technical summary
- Specifications
- Browser compatibility
- See also
- HTML
- Tutorials
- HTML basics
- Introduction to HTML
- Introduction to HTML overview
- Getting started with HTML
- What's in the head? Metadata in HTML
- HTML text fundamentals
- Creating hyperlinks
- Advanced text formatting
- Document and website structure
- Debugging HTML
- Assessment: Marking up a letter
- Assessment: Structuring a page of content
- Multimedia and embedding
- Multimedia and embedding overview
- Images in HTML
- Video and audio content
- From object to iframe — other embedding technologies
- Adding vector graphics to the web
- Responsive images
- Assessment: Mozilla splash page
- HTML tables
- HTML tables overview
- HTML table basics
- HTML table advanced features and accessibility
- Assessment: Structuring planet data
- References
- HTML elements
- <a>
- <abbr>
- <acronym> Deprecated
- <address>
- <area>
- <article>
- <aside>
- <audio>
- <b>
- <base>
- <bdi>
- <bdo>
- <big> Deprecated
- <blockquote>
- <body>
- <br>
- <button>
- <canvas>
- <caption>
- <center> Deprecated
- <cite>
- <code>
- <col>
- <colgroup>
- <data>
- <datalist>
- <dd>
- <del>
- <details>
- <dfn>
- <dialog>
- <dir> Deprecated
- <div>
- <dl>
- <dt>
- <em>
- <embed>
- <fencedframe> Experimental
- <fieldset>
- <figcaption>
- <figure>
- <font> Deprecated
- <footer>
- <form>
- <frame> Deprecated
- <frameset> Deprecated
- <h1>
- <head>
- <header>
- <hgroup>
- <hr>
- <html>
- <i>
- <iframe>
- <img>
- <input>
- <ins>
- <kbd>
- <label>
- <legend>
- <li>
- <link>
- <main>
- <map>
- <mark>
- <marquee> Deprecated
- <menu>
- <meta>
- <meter>
- <nav>
- <nobr> Deprecated
- <noembed> Deprecated
- <noframes> Deprecated
- <noscript>
- <object>
- <ol>
- <optgroup>
- <option>
- <output>
- <p>
- <param> Deprecated
- <picture>
- <plaintext> Deprecated
- <portal> Experimental
- <pre>
- <progress>
- <q>
- <rb> Deprecated
- <rp>
- <rt>
- <rtc> Deprecated
- <ruby>
- <s>
- <samp>
- <script>
- <search>
- <section>
- <select>
- <slot>
- <small>
- <source>
- <span>
- <strike> Deprecated
- <strong>
- <style>
- <sub>
- <summary>
- <sup>
- <table>
- <tbody>
- <td>
- <template>
- <textarea>
- <tfoot>
- <th>
- <thead>
- <time>
- <title>
- <tr>
- <track>
- <tt> Deprecated
- <u>
- <ul>
- <var>
- <video>
- <wbr>
- <xmp> Deprecated
- Global attributes
- accesskey
- anchor Experimental Non-standard
- autocapitalize
- autocorrect Experimental
- autofocus
- class
- contenteditable
- data-*
- dir
- draggable
- enterkeyhint
- exportparts
- hidden
- id
- inert
- inputmode
- is
- itemid
- itemprop
- itemref
- itemscope
- itemtype
- lang
- nonce
- part
- popover
- slot
- spellcheck
- style
- tabindex
- title
- translate
- virtualkeyboardpolicy Experimental
- writingsuggestions
- Attributes
- accept
- autocomplete
- capture
- crossorigin
- dirname
- disabled
- elementtiming
- for
- max
- maxlength
- min
- minlength
- multiple
- pattern
- placeholder
- readonly
- rel
- required
- size
- step
- <input> types
- <input type="button">
- <input type="checkbox">
- <input type="color">
- <input type="date">
- <input type="datetime-local">
- <input type="email">
- <input type="file">
- <input type="hidden">
- <input type="image">
- <input type="month">
- <input type="number">
- <input type="password">
- <input type="radio">
- <input type="range">
- <input type="reset">
- <input type="search">
- <input type="submit">
- <input type="tel">
- <input type="text">
- <input type="time">
- <input type="url">
- <input type="week">
- Guides
-
- Content categories
- Block-level elements
- Inline elements
- Quirks Mode and Standards Mode
- Date and time formats used in HTML
- Constraint validation
- Microdata
- Microformats
- Viewport meta tag
- Allowing cross-origin use of images and canvas
- Try it
- Attributes
- Usage notes
- Accessibility
- Examples
- Technical summary
- Specifications
- Browser compatibility
- See also
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
Attributes
These elements only include the global attributes.
Usage notes
- 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
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).
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.
Prefer using only one <h1> per page and nest headings without skipping levels.
Accessibility
Navigation
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:
html<h1>Heading level 1</h1> <h3>Heading level 3</h3> <h4>Heading level 4</h4>Prefer this:
html<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 content hierarchy and navigate to different headings.
Given the following page structure:
html<h1>Beetles</h1> <h2>Etymology</h2> <h2>Distribution and Diversity</h2> <h2>Evolution</h2> <h3>Late Paleozoic</h3> <h3>Jurassic</h3> <h3>Cretaceous</h3> <h3>Cenozoic</h3> <h2>External Morphology</h2> <h3>Head</h3> <h4>Mouthparts</h4> <h3>Thorax</h3> <h4>Prothorax</h4> <h4>Pterothorax</h4> <h3>Legs</h3> <h3>Wings</h3> <h3>Abdomen</h3>Screen readers would generate a list like this:
-
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.
- Headings • Page Structure • WAI Web Accessibility Tutorials
- MDN Understanding WCAG, Guideline 1.3 explanations
- Understanding Success Criterion 1.3.1 | W3C Understanding WCAG 2.0
- MDN Understanding WCAG, Guideline 2.4 explanations
- Understanding Success Criterion 2.4.1 | W3C Understanding WCAG 2.0
- Understanding Success Criterion 2.4.6 | W3C Understanding WCAG 2.0
- Understanding Success Criterion 2.4.10 | W3C Understanding WCAG 2.0
Labeling 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
html<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.
- Using the aria-labelledby attribute
- Labeling Regions • Page Structure • W3C WAI Web Accessibility Tutorials
Examples
All headings
The following code shows all the heading levels, in use.
html<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>Example page
The following code shows a few headings with some content under them.
html<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>Technical summary
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 |
Specifications
Specification |
---|
HTML Standard # the-h1,-h2,-h3,-h4,-h5,-and-h6-elements |
Browser compatibility
html.elements.h1
BCD tables only load in the browser
html.elements.h2
BCD tables only load in the browser
html.elements.h3
BCD tables only load in the browser
html.elements.h4
BCD tables only load in the browser
html.elements.h5
BCD tables only load in the browser
html.elements.h6
BCD tables only load in the browser
See also
- <p>
- <div>
- <section>
Help improve MDN
Was this page helpful to you?YesNoLearn how to contribute.This page was last modified on Oct 11, 2024 by MDN contributors.
View this page on GitHub • Report a problem with this contentTừ khóa » H2 Vs H1 Html
-
H1 Vs. H2 Heading Tags: Here's The Difference
-
HTML H1 To H6 Tag - W3Schools
-
Header Tags: A Simple (But Complete) Guide To H1, H2 And H3 Tags
-
H1 Vs H2 Vs H3: What Are Heading Tags And How To Use Them?
-
How To Use H1, H2, And H3 Header Tags For SEO Effectively
-
What Is The Difference Between H1, H2 Tag And Alt Tag In SEO?
-
Using H1, H2, H3 Heading Tags For SEO And UX • LockedownSEO
-
Why Use H1, H2, H3 Tags For Your SEO? - Semji
-
Heading Tags (H1, H2, H3, P) In HTML - Accessibility At Penn State
-
HTML Heading Tags: The SEO Guide For H1 - H6 - SE Ranking
-
Why H1 And H2 Header Tags Are Important To SEO
-
H1-H6 Heading Tags And SEO: The Ultimate Guide - ContentKing
-
When Using HTML Heading Elements (eg H1, H2, H3), What Hierarchy ...