← Blog · · ConvertCaseHQ Team · 6 min read

Markdown Headings: What's H1, H2, H3 and When to Use Them

In Markdown, a heading is a line that starts with one to six # characters followed by a space: # makes an H1, ## an H2, ### an H3. Use a single H1 for the page title, H2s for the main sections, and H3s for subsections inside an H2, without skipping levels. That outline is what screen-reader users navigate by. Google says heading order doesn't matter to Google Search, so get the hierarchy right for your readers.

Markdown heading syntax

The # style is called an ATX heading, and it's the one you'll use almost all the time:

# Page title (H1)

## Main section (H2)

### Subsection (H3)

#### Rarely needed (H4)

The CommonMark specification, which GitHub and many other tools build on, pins down the details:

  • One to six hashes. Seven (#######) is not a heading; it renders as a normal paragraph.
  • A space after the hashes. #hashtag and #5 bolt are paragraphs, not headings. The spec notes that many implementations don't require the space, so a file can render differently in different tools. Always add it.
  • Up to three spaces of indentation. Indent four and you get a code block instead.
  • Optional closing hashes. ## Setup ## is the same H2 as ## Setup. Most people leave them off.
  • Inline formatting works. Emphasis and code inside a heading are rendered, though plain words make better headings.

ATX vs Setext headings

Markdown also has an older underline style, called Setext. A line of text underlined with = becomes an H1, and one underlined with - becomes an H2:

Page title
==========

Main section
------------

Setext headings look nice in a plain-text file, but they only go two levels deep, so any document with H3s ends up mixing two styles. They're also behind a classic Markdown accident. Look at this:

We shipped the new release today.
---
Next up: the migration guide.

If you meant that --- to be a horizontal rule, you've actually turned the first line into an H2. The spec says that when a line of dashes could be either a thematic break or a Setext underline, the heading interpretation wins. Put a blank line above the ---, or use *** for rules.

Our advice: use ATX everywhere. If your team uses a linter, markdownlint's MD003 rule (heading-style) can enforce one style across a repository.

One H1 per page: where does it come from?

The H1 is the page title. The HTML standard technically allows more than one, but MDN's reference on heading elements calls a single <h1> per page the best practice, and Google's developer documentation style guide says to "only use a level-1 heading once on a page." A single, clear H1 also helps search engines: Google's documentation on title links suggests making the main title stand out, for example by putting it in the first visible <h1>. (More on that in our guide to writing blog titles for search.)

The tricky part is knowing who writes the H1:

  • A README or plain Markdown document: you do. The first line starting with # is the title, and everything else starts at ##.
  • A blog post or docs page in a static-site generator or CMS: often the template does. Many themes render the title from the front matter as the page's H1, so if your Markdown also opens with #, the page ends up with two. Check by inspecting a published page; if the title is already an <h1>, start your body at ##.

markdownlint understands this convention too. Its MD025 rule (single-h1) treats a title property in YAML front matter as the top-level heading, and flags any # heading that follows it.

Heading hierarchy for accessibility (and SEO)

Headings are how many screen-reader users get around a page. They jump from heading to heading, or pull up a list of every heading, to find the section they need. A skipped level is confusing in that list: the listener hears an H4 directly after an H2 and wonders what they missed. The W3C's tutorial on headings puts it this way: skipping heading ranks "can be confusing and should be avoided where possible."

Here's the shape to aim for:

# Beetles                    <- H1: the page
## Anatomy                    <- H2: main section
### Head                      <- H3: inside Anatomy
### Legs
## Habitat                    <- back to H2: fine
#### Forests                  <- skipped H3: avoid

Note that going back up is fine. The same W3C tutorial says it's OK for an H2 to follow an H4, because that just closes the previous section. Only skipping down is the problem.

Two habits break hierarchy more than anything else:

  • Choosing a level for its size. If ### looks too small in your theme, change the CSS. MDN is explicit that heading elements shouldn't be used to resize text.
  • Fake headings. A line of bold text like **Step 1** looks like a heading but isn't one, so it's invisible to anyone navigating by headings. If it introduces a section, make it a real heading.

What about SEO? Google is unusually direct here. Its SEO Starter Guide says semantic heading order is "fantastic for screen readers," but from Google Search's perspective "it doesn't matter if you're using them out of order," and there's no ideal number of headings. The same guide does recommend breaking long content into sections with headings so it's easier to read. So the SEO benefit of good headings is indirect: they make the page easier to scan and understand. That's reason enough. For more on how assistive technology handles text, see our guide to writing for screen readers.

One more opinion: if you regularly need H4s, the page may be trying to do too much. Splitting it into two pages often helps more than another level of nesting.

GitHub heading anchors and section links

On GitHub, every heading in a Markdown file gets an automatic anchor, so you can link straight to a section. GitHub documents the rules:

  • Letters are converted to lowercase.
  • Spaces become hyphens; other whitespace and punctuation are removed.
  • Leading and trailing whitespace is removed, and so is markup like _italics_.
  • If two headings would produce the same anchor, the later ones get -1, -2 and so on.
## Sample Section          ->  #sample-section
## Install & Configure     ->  #install--configure
## FAQ                     ->  #faq
## FAQ                     ->  #faq-1

See [the install steps](#install--configure).
See [setup docs](docs/setup.md#sample-section).

The second example catches people out: the ampersand is deleted, both spaces around it turn into hyphens, and you get a double hyphen. The safest way to get an anchor is to hover over the rendered heading on GitHub, click the link icon that appears, and copy the address. GitLab and static-site generators use similar rules that differ in the details, so check the platform you publish on.

The Slugify option in our case converter is close but not the same. It collapses runs of punctuation and spaces into a single hyphen (so install-configure) and strips accents, which suits URLs better than GitHub anchors.

Finally, anchors follow the heading text. Rename a heading and every link to it breaks, as GitHub's own docs warn. If a section is linked from elsewhere, think twice before rewording its heading, or add a custom anchor with <a name="install"></a> that won't change.

Markdown headings checklist

  • ATX style (#) with a space after the hashes.
  • Exactly one H1, whether you write it or your template does.
  • H2 for sections, H3 inside them, no skipped levels on the way down.
  • Real headings, never bold text pretending to be one.
  • Short, descriptive heading text that still makes sense in a list of headings.
  • A blank line before any --- you mean as a horizontal rule.

© 2026 ConvertCaseHQ. All rights reserved.