C.W.K.
Stream
Lesson 02 of 08 · published

Headings — # Through ######

~10 min · markdown, headings, structure

Level 0Plaintext
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Headings define the document outline

Markdown supports six heading levels using # (ATX-style). Headings are not decoration — they are the document outline. Screen readers, table-of-contents generators, and search engines all depend on them.

Hard rules

  • A space is required after the # characters. #heading with no space is not a heading in CommonMark.
  • You can optionally close headings: ## Section ##. The closing hashes are stripped.
  • Up to 6 levels — anything past ###### is just literal hashes.

Best practice

Use # H1 exactly once per document — that is your title. Structure the rest with ## for major sections and ### for subsections. Do not skip levels (H2 → H4 confuses screen readers and breaks auto-generated TOCs).

Setext-style — the alternate H1/H2 syntax

Underline text with = for H1 and - for H2. Older syntax, still valid, but ATX is more common because it works for all six levels and is easier to skim in source.

Trap: Some Markdown editors render #heading (no space) as a heading, but a CommonMark-compliant renderer (GitHub, pandoc, etc.) will not. Test on the platform you ship to.

Code

ATX-style headings·markdown
# Heading 1 — Page title
## Heading 2 — Major section
### Heading 3 — Subsection
#### Heading 4 — Sub-subsection
##### Heading 5 — Minor heading
###### Heading 6 — Smallest heading
Setext-style (H1 / H2 only)·markdown
Main Title
==========

Section Title
-------------

External links

Exercise

Take a recent README.md from any of your projects. Audit its outline: is the H1 unique? Are the H2s parallel (same level of importance)? Do you skip any level? Fix the heading hierarchy and notice how much more navigable the file becomes.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.