Sub topic 4
Headings: Levels, Order, and Emphasis
Headings are the part of a page's text hierarchy that people and software use to navigate. A sighted reader scans them to find a section. A screen reader user often pulls up a list of headings and jumps to one. Search engines and browser reading modes use them to work out what a page covers. This chapter covers how to choose heading levels, keep them in order, and give them visual emphasis without breaking their meaning.
What this chapter assumes
You should already know basic HTML elements, CSS selectors, and the font-size, font-weight, and color properties. You should also have read the earlier chapters on choosing elements by role and on building a type scale. This chapter uses the scale tokens (--text-xl, --leading-heading, and so on) without redefining them.
What a heading communicates
A heading element does two jobs at once:
- It labels the content that follows it, so a reader knows what a section is about.
- It places that section in a hierarchy. An
h2is a major section of the page, and anh3is a part of theh2above it.
The browser's default styles make headings large and bold, which is why people are tempted to pick a heading for its look. Resist that. The level you choose is a statement about structure. The size is a separate decision made in CSS.
Levels form an outline
HTML provides h1 through h6. Read in order, they form an outline, like the headings in a word processor's navigation pane.
The diagram matches the markup from the earlier chapter. The h1 names the whole page. Each h2 names a major section. The h3 elements split the Food section into smaller parts.
Rules for levels and order
Use one h1 that names the page
Give each page one h1 that describes the page's main subject. HTML technically allows several, but a single h1 gives screen reader users and search engines an unambiguous answer to "what is this page?" On a site with a header, the h1 usually belongs to the page's main content, not the site logo. The logo is a link or an image, not a heading.
Never skip a level going down
After an h2, the next heading may be another h2 (a sibling section) or an h3 (a child). It should not be an h4. A skipped level suggests a missing section, and a person navigating by headings will wonder what they missed.
Going back up is fine and expected. After an h3 you can write an h2 to start a new major section, or even jump from an h4 back to an h2. Only the downward direction needs to be gradual.
Choose the level by structure, not by size
If a design calls for a small heading in a sidebar, pick the level that fits the outline and then style it small. Here are two versions of the same sidebar, the first wrong and the second right.
<!-- Wrong: h5 chosen because it looks small -->
<aside>
<h5>Related reading</h5>
<ul>
<li><a href="/water">Treating water on the trail</a></li>
</ul>
</aside>
<!-- Right: level follows the outline; CSS controls the size -->
<aside>
<h2 class="heading-small">Related reading</h2>
<ul>
<li><a href="/water">Treating water on the trail</a></li>
</ul>
</aside>.heading-small {
font-size: var(--text-lg);
line-height: var(--leading-heading);
}A class like heading-small describes appearance and can be applied to any level. That is the separation between structure and styling this tutorial keeps returning to.
Do not use headings for things that are not headings
Headings are for naming sections. Do not use them for these cases:
- A tagline under the title. Use a
p, perhaps with a class such assubtitle. - Bold callout text in the middle of a paragraph. Use
strongor a styledp. - A line you want larger. Use a class.
A tagline marked up as an h2 adds an empty-feeling entry to the outline. Someone listing the page's headings sees "A short introduction to planning a multi-day hike" as if it were a section.
<header>
<h1>Trail Guide</h1>
<p class="subtitle">A short introduction to planning a multi-day hike.</p>
</header>Do not use bold paragraphs instead of headings
The opposite mistake is just as common. A p containing <strong>Gear</strong> looks like a heading, but assistive technology will not announce it as one, and it will not appear in any heading list. If a line names a section, make it a heading.
Sectioning elements and the outline
HTML has sectioning elements such as section, article, nav, and aside. An early version of the HTML specification described an "outline algorithm" in which a heading's level was computed from how deeply sections were nested, so you could use h1 everywhere. No browser or assistive technology ever implemented it, and it was removed from the specification.
The practical rule is simple. Write the explicit level you mean, regardless of nesting. Sectioning elements still help, because they give regions a name and a structure that screen readers expose as landmarks. A section is only exposed as a region when it has an accessible name, and the usual way to give it one is to point at its heading.
<section aria-labelledby="gear-heading">
<h2 id="gear-heading">Gear</h2>
<p>Start with footwear, then add layers.</p>
</section>Here the aria-labelledby attribute names the section using the heading's text. If you rename the heading, the section's name updates with it.
Emphasis: how headings stand out
Once the structure is right, you make headings visually stand out with CSS. Heading emphasis comes from several signals combined. No single one has to carry the whole job.
| Signal | How it works on headings | Typical choice |
|---|---|---|
| Size | Larger text is read as more important | A step up the type scale per level |
| Weight | Heavier strokes stand out from body text | `600` or `700` for headings, `400` for body |
| Spacing | Space above a heading separates it from the previous section | More space above than below |
| Color | A darker or different color adds distinction | Usually the same as body text, or slightly darker |
| Line height | Tighter leading keeps multi-line headings together | Around `1.2` |
Spacing groups the heading with its content
Space is the signal most often forgotten. A heading belongs to the text below it, so the gap above should be larger than the gap below. If the gaps are equal, the heading floats between two sections and readers must guess which one it names.
h2 {
font-size: var(--text-xl);
line-height: var(--leading-heading);
font-weight: 700;
margin-top: 2.5rem;
margin-bottom: 0.5rem;
}
h3 {
font-size: var(--text-lg);
line-height: var(--leading-heading);
font-weight: 600;
margin-top: 1.75rem;
margin-bottom: 0.5rem;
}
h2 + h3 {
margin-top: 0.75rem;
}The last rule handles a heading that directly follows another heading. Without it, the margins would leave a large, odd gap between a section title and its first subsection title.
Keep size differences distinct
Neighboring levels should look different from one another, and body text should look different from the lowest heading in use. If your h3 is 1.125rem and body text is 1rem, the difference is too small to read as a step. Weight can help in that case, but a clear gap in size is more reliable. The scale from the earlier chapter exists to prevent this.
Use weight and color sparingly
Making every heading bold and colored leaves nothing to separate levels. A common approach is to let size and weight vary across levels and keep color the same. If you do change color, check contrast. The contrast chapter covers the thresholds.
Do not nest emphasis inside headings
Wrapping words in strong inside a heading adds nothing. Headings are already prominent, and screen readers may announce the extra emphasis, which just adds noise. If you want part of a heading styled differently, a span with a class is the neutral tool.
<h1>Trail Guide <span class="edition">2026 edition</span></h1>.edition {
font-size: var(--text-base);
font-weight: 400;
}The span carries no meaning of its own, so screen readers read the whole line as a single heading.
Responsive heading size
Headings are the text that most needs to change across screen sizes. A 2rem h1 that works on a desktop can wrap to four lines on a narrow phone. The clamp() function covers this with one declaration, and the responsive chapter later in this tutorial treats it in depth. For now, notice that it applies to the heading size only. The level and the markup stay the same at every width.
h1 {
font-size: clamp(1.75rem, 1.2rem + 2vw, 3rem);
line-height: var(--leading-heading);
}Headings that are not visible
Occasionally a region has no visible title, for example a search form in a header, but a reader navigating by headings would benefit from one. You can add a heading and hide it visually while leaving it available to assistive technology.
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
border: 0;
}<nav aria-labelledby="footer-nav-title">
<h2 id="footer-nav-title" class="visually-hidden">Footer links</h2>
<ul>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>Do not use display: none for this. It removes the heading from the accessibility tree too, so the heading would be gone for the people it was meant for. Use this technique only when a hidden heading adds real navigation value, not to pad the outline.
Common errors
| Error | Why it causes trouble | Fix |
|---|---|---|
| `h1` followed by `h3` | Screen reader users hear a gap and wonder what was skipped | Use `h2`, or add the missing section |
| Several unrelated `h1` elements | The page's main subject is unclear | Keep one `h1`, make the rest `h2` |
| Tagline marked as `h2` | An empty-feeling entry appears in the heading list | Use a `p` with a class |
| Bold `p` used as a heading | Not announced or listed as a heading | Use a real heading element |
| Level picked for its default size | Outline no longer reflects structure | Choose by structure, size with CSS |
| `display: none` on a needed heading | Removed from the accessibility tree | Use a visually hidden class |
| Equal space above and below | The heading is not grouped with its content | Larger margin above, smaller below |
A quick way to audit headings
You can check the outline without special tools. Open the browser's developer console on the page and run this snippet. It prints each heading indented by its level and warns when a level is skipped.
let previous = 0;
document.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach((heading) => {
const level = Number(heading.tagName[1]);
const skipped = previous > 0 && level > previous + 1;
const indent = " ".repeat(level - 1);
console.log(
`${indent}h${level}: ${heading.textContent.trim()}${skipped ? " <-- skipped level" : ""}`
);
previous = level;
});Reading the printed list top to bottom is a good test. If you can understand the page's structure from that list alone, the headings are doing their job.
Exercise
A page has an h1, then an h2 titled "Setup", then an h4 titled "Install the CLI" because the designer wanted a smaller heading. What is wrong, and how do you fix it while keeping the small look?
Show answer
The h4 skips the h3 level, so the outline has a gap and screen reader users will wonder what is missing. Change the element to an h3, since "Install the CLI" is a child of "Setup", then reduce its size with a CSS class or rule, for example font-size: var(--text-lg);. The level follows the structure, and the size comes from CSS.
Exercise
A product page puts the line "Free shipping on orders over $50" in an h2 so it appears large and bold. Give two reasons this is a problem and describe a better approach.
Show answer
First, the line is not a section title, so it adds a meaningless entry to the page's heading list and misleads people navigating by headings. Second, it ties the visual size to a structural element, so changing the look later means changing the outline. Better: use a p with a class such as promo and set its size and weight in CSS.