Markdown Headings
Headings are the foundation of document structure. Markdown provides simple heading syntax with support for six heading levels.
Basic Syntax
Use # symbols to create headings, where the number of # symbols indicates the heading level:
Heading Levels
Heading Level 1 (H1)
Level 1 headings are typically used for document titles or chapter titles:
Heading Level 2 (H2)
Level 2 headings are used for main sections:
Heading Level 3 (H3)
Level 3 headings are used for subsections:
Level 4 to Level 6 Headings
Used for more refined content hierarchy:
Alternative Syntax
Setext Style Headings
Use = and - to create level 1 and level 2 headings:
Note: This method only supports level 1 and level 2 headings.
Heading Best Practices
1. Use Spaces
Add a space between the # symbol and the heading text:
2. Blank Lines Before and After Headings
Add blank lines before and after headings to improve readability:
3. Maintain Hierarchy Structure
Follow the heading hierarchy without skipping levels:
4. Avoid Using Too Many Levels
Usually 3-4 heading levels are sufficient:
5. Keep Headings Concise and Clear
Heading IDs
Some Markdown parsers automatically generate IDs for headings:
Generated HTML:
Custom Heading IDs
Some parsers support custom IDs:
Heading Links
Create Table of Contents
Use heading IDs to create a document table of contents:
Link to Heading
Heading Numbering
Manual Numbering
Automatic Numbering
Some editors and parsers support automatic numbering:
Heading Styles
Add Emojis
Add Icons
Headings and SEO
In web pages, headings are important for SEO:
Best Practices
- Use only one H1 per page: As the main heading
- Use by hierarchy: H1 → H2 → H3
- Include keywords: But naturally
- Keep it concise: Within 50-60 characters
Headings on Different Platforms
GitHub
GitHub automatically generates anchor links for headings:
You can link to this heading using #Installation Steps.
Blog Platforms
Most blog platforms support heading syntax and automatically generate tables of contents.
Documentation Tools
VitePress, Docusaurus and other tools automatically generate sidebar navigation.
Heading Shortcuts
VS Code
Ctrl/Cmd + Shift + ]: Increase heading levelCtrl/Cmd + Shift + [: Decrease heading level
Typora
Ctrl/Cmd + 1-6: Set heading level directlyCtrl/Cmd + 0: Set as paragraph
Obsidian
Ctrl/Cmd + 1-6: Set heading level
Practical Tips
1. Quickly Generate Table of Contents
Use tools to automatically generate table of contents:
2. Heading Templates
Create commonly used heading structure templates:
3. Use Heading Outline
Use the outline view in your editor for quick navigation:
- VS Code:
Ctrl/Cmd + Shift + O - Typora: Sidebar outline
- Obsidian: Right outline panel
Common Questions
Special Characters in Headings
Headings Too Long
If a heading is too long, consider:
- Simplifying the heading text
- Using a subheading
- Detailed explanation in the main text
Duplicate Headings
Avoid using the same heading text, or anchor link conflicts may occur:
Heading Checklist
- Used appropriate heading levels
- Blank lines before and after headings
- Space after
# - No skipping of heading levels
- Headings are concise and clear
- Only one H1 per page
- Headings reflect content
Summary
Headings are the skeleton of Markdown documents. Using headings properly can:
- Improve document readability
- Help readers quickly locate content
- Automatically generate table of contents and navigation
- Improve SEO effectiveness
Next: Learn detailed usage of Markdown Text Formatting.