Headings & Document Hierarchy (ATX vs Setext)
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).
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:
# 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:
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 (-):
- 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
- 1Only One H1 per Document: Treat
# Heading 1as the title of your article or README. Use## Heading 2for main chapters, and### Heading 3for subtopics. - 2Never Skip Heading Levels: Do not jump directly from an
# H1to an### H3without an intermediate## H2. Skipping levels breaks accessibility for screen-reader users. - 3Keep 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).
Paragraphs, Line Breaks & Horizontal Rules
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Environment & Editor Setup (VS Code, Obsidian, Typora) | Paragraphs, Line Breaks & Horizontal Rules |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.