Headings & Document Hierarchy (ATX vs Setext)0%

Headings & Document Hierarchy (ATX vs Setext)

Beginner12 min readUpdated: Jul 11, 2026
Study Materials

Headings establish the structural backbone of any document. They guide search engine crawlers (SEO), create clickable navigation outlines, and allow screen readers to parse the document hierarchy.

In Markdown, there are two distinct ways to create headings: ATX Style (using hash # symbols) and Setext Style (using underlines).

Markdown Syntax AnatomyClick to Zoom
Markdown Syntax Anatomy

1. ATX Headings (The Modern Standard)

ATX style headings are the most popular and versatile syntax in Markdown. You simply prefix the line with 1 to 6 hash symbols (#), followed by a space:

Markdown
# Heading 1 (Page Title / <h1>)
## Heading 2 (Major Section / <h2>)
### Heading 3 (Sub-section / <h3>)
#### Heading 4 (Component / <h4>)
##### Heading 5 (Minor detail / <h5>)
###### Heading 6 (Deepest sub-item / <h6>)
Critical Rule: You MUST place a space between the last # and the heading text! - Correct: # Heading Title - Incorrect: #HeadingTitle (Many modern CommonMark parsers will treat this as a hashtag or plain text rather than a heading!)

Optional Closing Hashes (ATX Closed Style):

You can optionally close an ATX heading with matching hashes. The closing hashes are purely aesthetic and will not appear in the rendered output:

Markdown
### Architecture Overview ###

2. Setext Headings (Underline Style)

Setext (Structure Enhanced Text) is an older style that mimics ASCII email conventions by underlining text with equal signs (=) or hyphens (-):

Markdown
This is an H1 Heading
=====================
 
This is an H2 Heading
---------------------
  • Equal signs (=): Produce an <h1> tag.
  • Hyphens (-): Produce an <h2> tag.
  • Any number of underlines (even 3 like === or ---) is sufficient.
  • Limitation: Setext only supports levels 1 and 2 (<h1> and <h2>). It cannot create <h3> through <h6>.

3. Best Practices for Document Hierarchy

  1. 1
    Only One H1 per Document: Treat # Heading 1 as the title of your article or README. Use ## Heading 2 for main chapters, and ### Heading 3 for subtopics.
  2. 2
    Never Skip Heading Levels: Do not jump directly from an # H1 to an ### H3 without an intermediate ## H2. Skipping levels breaks accessibility for screen-reader users.
  3. 3
    Keep Headings Concise: Headings are used by documentation generators (like VitePress and Docusaurus) to automatically generate page anchors (#heading-slug) and sidebar Table of Contents.

Multiple Choice Questions

1. How many heading levels does ATX-style Markdown support?

A. 3 levels B. 6 levels (H1 to H6) C. 10 levels D. Unlimited levels Answer: B Explanation: ATX style supports up to 6 heading levels corresponding to HTML <h1> through <h6> using 1 to 6 hash symbols.


2. What character is used to create ATX style headings in Markdown?

A. Ampersand (&) B. Hash / Number sign (#) C. At sign (@) D. Asterisk () Answer: B Explanation:* The hash symbol (#) at the beginning of a line defines an ATX heading.


3. In Setext style headings, which heading levels can be created?

A. Levels 1 and 2 only (H1 and H2) B. Levels 1 through 6 C. Level 3 only D. All levels except H1 Answer: A Explanation: Setext style only supports H1 (underlined with =) and H2 (underlined with -).


4. Why must a space follow the hash symbol in '# Heading'?

A. To save hard disk memory B. The CommonMark specification strictly requires a space to distinguish headings from social hashtags or code comments C. The computer will crash without it D. It increases internet download speed Answer: B Explanation: CommonMark requires a whitespace character after the hashes to avoid accidental heading generation from hashtags like #typescript.


5. What HTML tag is generated by '### Database Configuration'?

A. <h1> B. <h2> C. <h3> D. <p> Answer: C Explanation: Three hash symbols produce an HTML <h3> tag (third-level heading).


Next Lesson

Paragraphs, Line Breaks & Horizontal Rules

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext