Markdown Headings to HTML h1-h6 Tags
Learn how Markdown headings (#, ##, ###) convert to HTML h1 through h6 tags. Includes ATX-style and Setext-style heading syntax with practical examples.
Detailed Explanation
Markdown Headings to HTML
Markdown supports six levels of headings, corresponding to HTML <h1> through <h6> tags. There are two styles for writing headings in Markdown: ATX-style and Setext-style.
ATX-Style Headings
ATX-style headings use hash characters (#) at the beginning of the line:
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
This converts to the following HTML:
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
The number of # characters determines the heading level. A space after the # is required by most parsers for correct rendering.
Setext-Style Headings
Setext-style headings only support two levels. An underline of = creates an <h1>, and an underline of - creates an <h2>:
Heading 1
=========
Heading 2
---------
Best Practices
- Use only one
<h1>per page for SEO — it should be the page title. - Do not skip heading levels (e.g., jumping from
h2toh4). - Keep headings concise and descriptive.
- Add a blank line before and after each heading for readability.
Use Case
Headings are essential for structuring any document. When writing README files, blog posts, documentation, or technical articles in Markdown, headings define the hierarchy and make content scannable for both readers and search engines.