← Back to HTML & CSS, page 3

html-css-0053 · Easy fresher

How should heading levels h1 to h6 be used on a page?

Headings form the outline of a page. Use one h1 for the page title, h2 for main sections and h3 to h6 for parts inside them, without skipping levels downwards. Choose the level for structure and use CSS for size.

Full answer

Headings give a page an outline. h1 is the main title, h2 marks the major sections, h3 the parts inside a section, and so on down to h6. Think of the contents page of a textbook: chapter, topic, sub-topic.

Rules that work well in practice:

  • Use one h1 that names the page. The HTML specification allows more than one, but a single h1 gives the clearest outline for people and tools.
  • Do not skip levels going down. An h3 directly after an h1 leaves a hole in the outline.
  • Choose a heading level for structure, never for size. If an h2 looks too big, change its CSS.
  • Keep headings short and meaningful, so a list of them reads like a summary.
  • Do not use a heading for text that is only bold or large, such as a price or a quote.

Screen reader users often jump from heading to heading, or open a list of all headings, to find their way. Search engines also read headings to understand what each part is about.

The script prints the order of levels used, reports no skipped levels for this page, and reports h1 to h3 for the broken list [1, 3, 2]. A check like this is easy to add to a test or a linter.

A heading can go up any number of levels, for example from an h3 back to an h2. Only jumping down by more than one level leaves a gap.

html
<main>
  <h1>Web Development Course</h1>
  <h2>Week 1: HTML</h2>
  <h3>Elements and attributes</h3>
  <h3>Forms</h3>
  <h2>Week 2: CSS</h2>
  <h3>The box model</h3>
</main>
<pre id="out"></pre>
<script>
  function skipped(levels) {
    const gaps = [];
    for (let i = 1; i < levels.length; i++) {
      if (levels[i] > levels[i - 1] + 1) gaps.push("h" + levels[i - 1] + " to h" + levels[i]);
    }
    return gaps.length ? gaps.join(", ") : "none";
  }
  const levels = [...document.querySelectorAll("h1,h2,h3,h4,h5,h6")].map(h => Number(h.tagName[1]));
  document.getElementById("out").textContent =
    "outline: " + levels.map(l => "h" + l).join(" > ") + "\n" +
    "skipped on this page: " + skipped(levels) + "\n" +
    "skipped in [1, 3, 2]: " + skipped([1, 3, 2]);
</script>

Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.

Key points

  • h1 names the page; h2 to h6 build the outline below it.
  • Do not skip levels when going down, such as h1 straight to h3.
  • Level is for structure; size belongs to CSS.
  • Screen reader users and search engines both read headings to understand the page.
  • Do not use headings for text that is only bold or large.

Common mistakes

  • Picking h3 or h4 because the default size looks right. Fix the size in CSS and keep the level honest.
  • Using several h1 elements in different parts of the page without a clear reason, which blurs the main topic.
  • Making the logo or the site name the h1 on every page, so every page has the same main heading.

Follow-ups

  • Is it valid to have more than one h1 on a page?
  • How would you automatically detect skipped heading levels?

Tips

  • Describe the outline test: read only the headings and check that the page still makes sense. It is a quick way to review your own page.
  • Mention screen reader heading navigation. It is the practical reason the order matters.