Headings <h1>–<h6>

HTML Living Standard

Headings give a page a readable hierarchy. Each level tells the reader where a section fits under the page title and other sections.

On this page

Heading levels and hierarchy

Use h1 for the page’s main topic. Use h2 for each major section and h3 for a subsection inside an h2 section. Use h4 through h6 for deeper levels when needed. When opening a subsection, move down one level at a time. When you finish that subsection, you can go back to a higher level. A screen-reader user can navigate through these levels to find a section.

How to try it In index.html, replace the content between <body> and </body> with this example. Save the file and reload it in the browser.

<h1>Community library</h1>
<h2>Books</h2>
<h3>Fiction</h3>
<p>Novels and short stories.</p>
<h3>Nonfiction</h3>
<p>History and science books.</p>
<h2>Events</h2>
<p>Reading groups and workshops.</p>

What to expect Books and Events are both level 2. Fiction and Nonfiction are level 3 under Books. The default font size usually reflects the level, but the elements define the structure.

Heading appearance with CSS

Pick the heading level based on where it belongs in the document. Use CSS font-size and margins to adjust its visual size and spacing. For example, a compact card section can still use an h2 even if its design uses a small heading.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Heading style</title>
  <style>
    .compact-heading { font-size: 1rem; }
  </style>
</head>
<body>
<h1>Community library</h1>
<h2 class="compact-heading">Today’s specials</h2>
</body>
</html>

What to expect “Today’s specials” looks smaller and still has level 2 semantics, which you can verify in the browser accessibility tree.

Official references