# Headings & the Outline

> The six heading ranks build the outline of your page. Used in order, they let people and screen readers grasp the structure at a glance.

Subject: HTML | Lesson 5 of 42 | 6 min read
Interactive lesson: https://codewithanimation.in/html/headings-and-outline
Previous: [HTML Entities & Special Characters](https://codewithanimation.in/html/html-entities.md) | Next: [Paragraphs & Breaks](https://codewithanimation.in/html/paragraphs-and-breaks.md)

## What it is

HTML gives you six heading ranks, `<h1>` down to `<h6>`. `<h1>` is the highest rank and `<h6>` the lowest. Together they form the outline of the page, the same way a table of contents shows a document's structure.

A heading marks the start of a section and says how important that section is relative to the others. It is about meaning and hierarchy, not about making text look big. The default sizes are just a visual hint of the rank underneath.

## Why it matters

Headings are how a lot of people move around a page. Screen reader users jump from heading to heading and can pull up a list of every heading to understand the layout in seconds, so a clean outline is real navigation, not decoration.

Search engines read the same outline to understand what your page is about. Get the ranks right and your structure is legible to humans, assistive tech, and crawlers all at once, from one set of tags.

## How it works

Start every page with a single `<h1>` that names the whole page, much like the `<title>`. Then nest sections by rank: an `<h2>` for each major section, an `<h3>` for a subsection inside it, and so on. The rule is to go in order and never skip a level on the way down, so `<h1>` then `<h2>` then `<h3>`, not `<h1>` straight to `<h3>`. Coming back up is fine: you can close an `<h4>` subsection and start the next `<h2>`.

Choose a rank by where the section sits in the hierarchy, never by how the text should look. If a heading is too big or too small, change its size with CSS `font-size`, not by switching to a different heading level.

One thing that surprises people: the sectioning elements like `<section>` and `<article>` do not adjust heading ranks for you. The old document outline algorithm was never actually implemented in browsers or screen readers, and the default style that shrank an `<h1>` inside a `<section>` was removed from the standard in 2025. So you still set the correct `<h1>` to `<h6>` yourself, even inside a `<section>`.

## Common mistake: Picking a heading level by how big it looks

It is tempting to use an `<h4>` because the text comes out the size you want, or to jump from `<h1>` to `<h3>` to skip a size. That breaks the outline: a screen reader user hears a missing level and wonders what they skipped. Choose the rank by the section's place in the hierarchy, then use CSS `font-size` to make it any size you like.

## Tip: Read your headings alone as a table of contents

Strip everything but the headings and read them top to bottom. If they make sense as an outline, with one `<h1>`, no skipped levels, and ranks that match how sections nest, your structure is sound. This is exactly what a screen reader presents, so it is the fastest way to catch a broken hierarchy.

## Try it: Try it

Change the level of the third heading and watch the outline update. Pick `h3` and it nests cleanly under Pizza; jump to `h4` and you skip a level.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/headings-and-outline

## Check yourself

### Question 1

After an <h2>, which heading can come next inside that section?

- A. <h3>, because you should not skip a level going down
- B. <h4>, to make the text a bit smaller
- C. Any level you like; the order does not matter

Correct answer: A

Go in order without skipping on the way down: `<h2>` is followed by `<h3>`. Skipping a level leaves screen reader users wondering what heading is missing.

- Why not B: Jumping h2 to h4 skips h3 and breaks the outline. Use CSS to change size instead.
- Why not C: Order is exactly what matters: the ranks build the outline people navigate by.

### Question 2

You put an <h1> inside a <section>. What rank is it?

- A. Still an h1; <section> does not change heading ranks
- B. Automatically demoted to an h2 by the outline algorithm
- C. It becomes invalid and is ignored

Correct answer: A

Sectioning elements never adjust heading ranks. The document outline algorithm does not work in any browser or screen reader, so set explicit `<h1>` to `<h6>` ranks yourself.

- Why not B: That algorithm was never implemented, and the related default style was removed in 2025.
- Why not C: It is valid, it just stays an h1. You must set the rank you actually want.

### Question 3

What is the right reason to choose <h2> over <h3>?

- A. Because the section is one level up in the page's hierarchy
- B. Because h2 renders at the font size you want
- C. Because h2 is more common than h3

Correct answer: A

Heading rank reflects position in the outline. Pick the level by hierarchy, then style the size with CSS `font-size` if you want it bigger or smaller.

- Why not B: Size is a CSS decision. Headings encode structure, not appearance.
- Why not C: Frequency is irrelevant; the rank must match where the section sits.

## Remember this

- `<h1>` to `<h6>` are six ranks that form the page outline; `<h1>` is highest, `<h6>` lowest.
- Use one `<h1>` per page and never skip a level going down (`<h1>` then `<h2>` then `<h3>`).
- Choose a rank by hierarchy, not by size; change size with CSS `font-size` instead.
- `<section>` and `<article>` do not auto-adjust ranks; set every heading level yourself.
