Markdown by Example: Headings
Headings are used to structure your document. This sample shows the six levels of headings available in Markdown.
Code
# Heading Level 1
## Heading Level 2
### Heading Level 3
#### Heading Level 4
##### Heading Level 5
###### Heading Level 6
Alternative Syntax for H1
=========================
Alternative Syntax for H2
-------------------------Explanation
Headings in Markdown are created using the hash symbol #. The number of hash symbols corresponds to the heading level, from 1 to 6. For example, a single # creates a top-level heading (<h1>), while ### creates a third-level heading (<h3>). It is important to place a space between the hashes and the heading text for compatibility with all Markdown parsers.
There is also an alternative syntax for the first two heading levels, known as Setext headings. For a level 1 heading, you underline the text with equals signs =. For a level 2 heading, you use hyphens -. The length of the underline doesn't strictly matter, but making it match the text length looks better in the raw file.
Proper use of headings is crucial for document accessibility and SEO. You should generally have only one H1 per page (the title), followed by H2s for main sections, H3s for subsections, and so on. This creates a logical outline that screen readers and search engines can easily understand.
Code Breakdown
# Heading Level 1 corresponds to the HTML <h1> tag.=== underlines indicate an H1. This style is often used in plain text emails.
