Markdown: Markdown Heading Syntax and Hierarchy Guidelines
Last updated: 2026-10-14
Headings are the skeleton of your document — they tell both readers and search engines how your content is organized.
1. What You'll Learn
- Both Markdown heading syntaxes: ATX and Setext
- How to use the six heading levels correctly
- Heading hierarchy rules and best practices
- Common heading mistakes and how to fix them
- How headings affect SEO and accessibility
2. A Document Maintainer's Real Story
(1) Pain Point: Chaotic Heading Hierarchy
Sarah took over a technical blog project and found that past articles used headings haphazardly — some used #, some used ##, some had no headings at all, and others jumped from H1 straight to H3, skipping H2 entirely. As a result, the site's table of contents generator was completely broken, and readers complained they couldn't find content.
(2) Solution: Standardized Heading Rules
Sarah established heading rules: each article has only one # heading, and headings must progress step by step (## → ### → ####) without skipping levels. She used a script to fix all 50 articles in bulk. After the fix, the auto-generated table of contents worked again, and reader time-on-page increased by 40%.
3. Two Heading Syntaxes
Markdown provides two heading syntaxes:
graph TB
A[Markdown Headings] --> B[ATX Style]
A --> C[Setext Style]
B --> D[# through ######]
B --> E[Most common]
C --> F[=== and ---]
C --> G[H1 and H2 only]
| Syntax | Notation | Supported Levels | Best For |
|---|---|---|---|
| ATX | # through ###### |
H1–H6 | All scenarios, most universal |
| Setext | === / --- |
H1, H2 only | Niche editor preference, poor compatibility |
(1) ATX Style (Recommended)
ATX style uses the number of # symbols to indicate heading level — one # for H1, two ## for H2, and so on:
# before the heading text; otherwise, some parsers won't recognize it as a heading.
(2) Setext Style
Setext style places === or --- under the heading text:
▶ Example: Comparing the Two Heading Styles
4. Heading Hierarchy Guidelines
(1) Using Hierarchy Correctly
Document headings should have a clear hierarchy, like the table of contents of a book:
H2 → H2 is perfectly fine.
(2) Impact on SEO and Accessibility
Heading hierarchy matters a lot for SEO and screen readers:
| Aspect | Recommended | Avoid |
|---|---|---|
| H1 count | One per page | Multiple H1s confuse search engines |
| Keywords | H1 contains core terms, H2 contains related terms | Keyword stuffing |
| Hierarchy | Step by step, no level skipping | Chaotic H1→H3→H2 jumps |
| Length | H1 ≤ 60 chars, H2 ≤ 40 chars | Entire paragraphs as headings |
▶ Example: Correct vs. Incorrect Heading Hierarchy
5. Formatting and Special Characters in Headings
(1) You Can Use Bold, Italic, and Code in Headings
(2) Avoid Overly Long Heading Content
▶ Example: Before and After Heading Optimization
6. Full Example: Heading Structure of an Article
Expected result: A clearly layered document structure that both readers and search engines can quickly understand.
❓ FAQ
# and the heading text required?#Title won't be recognized as a heading — it will be treated as plain text. # Title is the correct way.{#custom-id}.📖 Summary
- Two heading syntaxes: ATX (
#) and Setext (===); recommend using ATX throughout - Always put a space after
#, or it won't be recognized as a heading - One H1 per page, progress step by step without skipping levels
- Keep headings short (H1 ≤ 60 chars); avoid keyword stuffing
- Headings can include code, bold, italic, and other formatting
- A good heading hierarchy serves both readers and search engines
📝 Exercises
-
Beginner: Write a short Markdown piece with H1, H2, and H3 headings (choose the topic yourself — a reading note or study plan). Make sure each heading level has exactly one more
#than the level above it. -
Intermediate: Open a document you recently wrote and check if its heading hierarchy follows the rules. If there are level skips or messes, fix them. Then count how many H1s you have (the correct answer is 1).
-
Challenge: Use the Markdown All in One extension in VS Code to generate a table of contents (type
[TOC]or use the command) and verify your heading hierarchy is correct. If the generated TOC looks off, your heading levels need adjusting.