Markdown Headings
Markdown headings organize documents into a clear hierarchy, making long pages easier to read, scan, and navigate. Whether you're writing a README, technical documentation, notes, or articles, headings help structure your content for both readers and Markdown editors.
This guide covers every Markdown heading level, ATX and Setext syntax, GitHub compatibility, heading hierarchy, anchor links, accessibility, and practical best practices with real examples.
💡 Practice as you read: Open the Markdown Editor to test heading syntax with live preview, or keep the Markdown Cheat Sheet nearby for quick syntax lookup.
What Are Markdown Headings?
Markdown headings define the structure of a document. Instead of changing font size or applying styles, you create headings by adding one or more # characters before your text.
Syntax#
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
Live Preview#
Each additional # creates a lower heading level, allowing you to organize content into sections and subsections that are easy to follow.
Most Markdown applications—including GitHub, GitLab, VS Code, Obsidian, and many static site generators—recognize this syntax and render it as HTML headings (<h1> through <h6>).
If you're new to Markdown, start with Markdown Basics before learning document structure.
Markdown Heading Levels
Markdown supports six heading levels. Each level has a specific role in creating a logical document outline.
| Level | Syntax | HTML | Best Use |
|---|---|---|---|
| H1 | # Heading |
<h1> |
Document or page title (usually one per document) |
| H2 | ## Heading |
<h2> |
Main sections |
| H3 | ### Heading |
<h3> |
Subsections |
| H4 | #### Heading |
<h4> |
Supporting topics |
| H5 | ##### Heading |
<h5> |
Rarely used nested sections |
| H6 | ###### Heading |
<h6> |
Deeply nested content |
Think of headings as an outline rather than styling. Each level should naturally fit beneath the level above it. For most README files and documentation pages, H1 through H3 are enough; H4–H6 are typically only needed in large technical documents.
A typical documentation page follows a structure like this:
# Project Documentation
## Installation
### Windows
### macOS
## Configuration
### Environment Variables
## FAQ
This hierarchy improves readability, makes large documents easier to navigate, and helps automatically generated Tables of Contents (TOCs) reflect the structure of your content.
Why Heading Hierarchy Matters
Headings do more than create larger text—they define the organization of your document.
A clear hierarchy helps:
- Readers quickly scan long pages.
- Documentation tools generate accurate Tables of Contents.
- Screen readers understand the relationship between sections.
- Teams maintain consistent documentation across projects.
Avoid choosing heading levels based only on appearance. An H3 isn't simply a smaller H2; it represents a subsection that belongs under an H2.
ATX vs Setext Headings
Markdown supports two ways to create headings: ATX headings (using #) and Setext headings (using underline characters).
While both are valid, modern Markdown editors and documentation projects almost always use the ATX style because it supports all six heading levels and is easier to maintain. Learn every formatting rule in the Markdown Syntax reference.
| Style | Syntax | Supports | Recommended |
|---|---|---|---|
| ATX | # Heading |
H1–H6 | |
| Setext | Heading + === or --- |
H1–H2 only | Limited use |
ATX Headings#
Syntax#
# Project Title
## Installation
### Configuration
Live Preview#
This is the standard style you'll find in GitHub repositories, documentation websites, knowledge bases, and Markdown editors.
Setext Headings#
Project Title
=============
Installation
------------
= creates an H1 heading, while - creates an H2 heading.
Because Setext only supports two heading levels, it isn't suitable for larger documents with multiple nested sections.
Recommendation: Use ATX headings for new Markdown documents unless you're maintaining older content that already uses the Setext style.
Building a Logical Heading Structure
Good Markdown documents are organized like an outline. Each heading level should naturally belong to the level above it.
# User Guide
## Getting Started
### Installation
### Configuration
## Features
### Authentication
### API Access
## Troubleshooting
Each H2 introduces a major topic, while H3 headings divide that topic into smaller sections.
This structure keeps documentation easy to navigate and helps readers understand how different sections relate to one another.
Heading Level ≠ Font Size
Heading levels define document structure, not visual size.
Choose H2 or H3 because they fit the document hierarchy—not because they appear larger or smaller on screen. If you only want different text styling, use CSS or your publishing platform's theme settings instead of changing heading levels.
This is one of the most common beginner mistakes: picking #### because it "looks right" instead of because the content is a fourth-level subsection under an H3.
When to Split Large Documents
If your document regularly reaches H5 or H6 headings, consider splitting it into multiple pages instead of creating deeply nested sections.
Large documentation projects are usually easier to navigate when related topics are organized into separate pages connected through internal links. For example, split a monolithic API guide into separate pages for Authentication, Endpoints, and Error Codes—each with its own H1 and a clear H2 outline.
Use the Documentation Index to link related guides, and preview how your outline reads in the Markdown Editor before publishing.
Real-World Examples
A typical project README often follows a structure like this:
# My Project
## Features
## Installation
## Quick Start
## Configuration
## Usage
## Contributing
## License
A longer documentation guide might include another level:
# API Documentation
## Authentication
### API Keys
### OAuth
## Endpoints
### Users
### Projects
### Billing
Both examples are easy to scan because each heading level follows a consistent hierarchy.
Need a complete Markdown overview? See the Markdown Syntax reference for all supported elements, or continue with Markdown Paragraphs to learn how headings and paragraphs work together in well-structured documents.
Heading Anchor Links
Many Markdown platforms automatically create anchor links for headings. These links let readers jump directly to a specific section instead of scrolling through the entire document.
For example, this heading:
## Installation Guide
may generate an anchor like:
#installation-guide
You can then link directly to that section:
[Go to Installation](#installation-guide)
This is commonly used in README files, long documentation pages, and automatically generated Tables of Contents.
Note: Anchor generation isn't part of the original Markdown specification. GitHub-specific behavior is covered in GitHub Flavored Markdown (GFM).
How GitHub Generates Heading IDs
GitHub automatically creates an ID for every heading when rendering Markdown.
In most cases GitHub:
- Converts text to lowercase.
- Replaces spaces with hyphens (
-). - Removes most punctuation.
- Adds numeric suffixes if multiple headings have the same name.
| Heading | Generated Anchor |
|---|---|
## Installation Guide |
#installation-guide |
## API Reference |
#api-reference |
## Getting Started |
#getting-started |
If the same heading appears more than once, GitHub automatically creates unique anchors:
#installation
#installation-1
#installation-2
This prevents duplicate IDs within the same document.
Related: Learn more about GitHub-specific behavior in the GitHub Flavored Markdown (GFM) guide.
Using Links, Emojis, and Inline Code in Headings
Most modern Markdown parsers allow inline formatting inside headings.
Links
## [API Documentation](https://example.com)
Inline Code
## Installing `npm`
Emojis
## 🚀 Getting Started
These elements are widely supported by GitHub, GitLab, Obsidian, and many documentation tools.
However, avoid adding excessive formatting inside headings, as it can make large documents harder to scan.
Headings and Table of Contents (TOC)
A well-structured heading hierarchy allows many tools to generate a Table of Contents (TOC) automatically.
# User Guide
## Installation
## Configuration
### Environment Variables
## Troubleshooting
can produce a navigation menu similar to:
User Guide
• Installation
• Configuration
• Environment Variables
• Troubleshooting
Many documentation platforms, static site generators, and Markdown editors build navigation directly from heading levels, making consistent hierarchy more important than visual appearance.
If you're creating large documentation projects, keep heading levels consistent so your TOC remains clean and easy to navigate.
Generate navigation automatically with the Markdown TOC Generator.
Markdown Headings Across Different Platforms
The basic heading syntax works consistently across most Markdown applications, but some platforms add features that improve navigation and document organization.
| Platform | Heading Behavior |
|---|---|
| GitHub | Automatically generates anchor links and builds a Table of Contents for supported pages. |
| GitLab | Supports heading anchors and documentation navigation similar to GitHub. |
| VS Code | Live Preview renders headings instantly and many extensions generate TOCs automatically. |
| Obsidian | Supports collapsible headings, outline view, backlinks, and heading navigation. |
| Notion | Converts imported Markdown headings into editable heading blocks. |
Although the syntax remains the same, navigation features such as heading anchors, outlines, folding, and automatic Tables of Contents depend on the application you're using.
Related: Learn more about platform differences in the GitHub Flavored Markdown (GFM) guide.
Accessibility and Document Structure
Headings don't just make documents look organized—they also provide structure that browsers, search engines, and assistive technologies rely on.
A logical heading hierarchy helps:
- Screen readers navigate documents efficiently.
- Readers scan long pages more quickly.
- Documentation tools generate accurate outlines.
- Search engines better understand page structure.
# User Guide
## Installation
### Windows
### macOS
## Configuration
### Environment Variables
## Troubleshooting
Each heading level builds on the one above it. Jumping between unrelated levels can make documents harder to understand, especially in long technical guides.
Best Practices for Markdown Headings
Well-written headings make documentation easier to maintain as projects grow.
Follow these recommendations:
- Use a single H1 for the document title.
- Keep headings concise and descriptive.
- Follow a logical H1 → H2 → H3 hierarchy.
- Leave one space after each
#. - Use sentence case or title case consistently throughout the document.
- Choose heading levels based on structure—not visual size.
- Keep similar sections at the same heading level.
Read Markdown Best Practices for writing consistent documentation across projects. Test your heading hierarchy in the Markdown Editor before publishing.
✅ Good
# User Guide
## Installation
## Configuration
## Troubleshooting
❌ Less effective
# User Guide
#### Installation
## Configuration
##### Troubleshooting
The second example creates an inconsistent outline that's harder for both readers and documentation tools to interpret.
Common Heading Mistakes
Most heading issues are caused by small formatting errors rather than incorrect Markdown syntax.
| Mistake | Better Approach |
|---|---|
##Heading |
Add a space: ## Heading |
| Skipping from H1 directly to H4 | Follow a logical hierarchy. |
| Using multiple H1 headings without a reason | Keep one H1 for the main document title. |
| Choosing heading levels only for appearance | Select levels based on document structure. |
| Writing long paragraph-style headings | Keep headings short and descriptive. |
If headings don't render correctly, check for missing spaces, inconsistent formatting, or unsupported Markdown features in your editor.
Documentation Tips
As documentation grows, consistent heading structure becomes more important than the headings themselves.
A few habits can make large projects easier to maintain:
- Use the same heading style across every document.
- Keep section names consistent between related guides.
- Avoid changing heading text unless necessary, as it may affect existing anchor links.
- Review the generated Table of Contents before publishing long documentation.
- Break very large sections into smaller H2 and H3 topics instead of creating long scrolling pages.
These small practices make documentation easier to navigate, maintain, and update over time.
For broader documentation standards, see Markdown Best Practices and the Markdown Style Guide. Preview your heading hierarchy in the Markdown Editor before publishing.
Frequently Asked Questions
- 1
Can I use multiple H1 headings in a Markdown document?
Technically, many Markdown parsers allow multiple H1 headings. However, most documentation projects, GitHub repositories, and knowledge bases use a single H1 as the document title and organize the remaining content with H2 and H3 headings. This creates a clearer document outline and improves navigation.
- 2
What's the difference between ATX and Setext headings?
ATX headings use # characters and support all six heading levels (H1–H6). Setext headings use underline characters (= and -) and only support H1 and H2. For new documents, ATX headings are generally recommended because they're easier to maintain and work consistently across Markdown editors.
- 3
How does GitHub create heading anchor links?
GitHub automatically generates anchor IDs from heading text by converting it to lowercase, replacing spaces with hyphens, and removing most punctuation. These generated IDs allow you to link directly to specific sections within a document.
- 4
Can I add links, emojis, or inline code inside a heading?
Yes. Most modern Markdown applications support inline formatting such as links, emojis, and inline code within headings. For example: ## 🚀 Getting Started with
npm. Support may vary slightly between Markdown parsers, so it's a good idea to preview your document before publishing. - 5
Why isn't my heading rendering correctly?
The most common causes are: missing a space after the #, using more than six # characters, incorrect indentation, or previewing the file in an editor that doesn't fully support Markdown. If the syntax looks correct, verify that your Markdown renderer supports the feature you're using.
- 6
Do headings automatically create a Table of Contents?
Markdown itself doesn't generate a Table of Contents. Many platforms—including GitHub, documentation generators, and Markdown editors—can build a TOC automatically from your heading hierarchy. Using consistent H2 and H3 headings helps these tools generate accurate navigation.
- 7
Can I skip heading levels?
Markdown allows it, but it's generally discouraged. For example, jumping directly from an H2 to an H4 makes the document structure less clear and can reduce accessibility. Keeping headings in sequence creates a more logical outline.
- 8
Which heading levels should I use most often?
For most README files, documentation, tutorials, and knowledge base articles: H1 for the document title, H2 for main sections, and H3 for subsections. H4–H6 are mainly useful for large technical documents with deeply nested content.
