MDUtil

Headings in Markdown

Start a line with # and a space to make a heading: one # for the main title, ## for sections, up to six levels. This guide covers the levels, the underlined style, ids and common mistakes.

Quick answer

How do you make a heading in Markdown?

Start the line with one to six # signs and a space: # Title is the largest heading and ###### Note the smallest. They become the HTML elements <h1> to <h6>. Use one # heading for the document title and ## for its sections.

Markdown
# Document title

## Section

### Subsection

Result

Document title
Section
Subsection

Heading syntax and examples

The number of # signs sets the level. A few details decide whether a line becomes a heading at all.

The six levels

Each extra # goes one level down. Most documents need only the first three.

Markdown
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6

Result

Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6

A space after the hashes

Without the space, the line stays an ordinary paragraph.

Markdown
#No space, no heading

# With a space

Result

#No space, no heading

With a space

Underlined headings

A line of = or - under the text makes a level 1 or level 2 heading. This style has only these two levels.

Markdown
Main title
==========

Section title
-------------

Result

Main title
Section title

Closing hashes

Hashes after the text are optional and are left out of the heading.

Markdown
## Installation ##

Result

Installation

Formatting in headings

Headings can hold bold text, inline code and links.

Markdown
### The `--force` option

### **Breaking** changes in [version 2](https://example.com/v2)

Result

The --force option
Breaking changes in version 2

Custom heading ids

Pandoc, Hugo and kramdown accept an id in braces after the heading text, which # links can point to.

Markdown
## Installation {#install}

[Jump to Installation](#install)

Pandoc, Hugo and kramdown only. Other Markdown apps display this differently, so there is no preview.

Headings in popular apps

# headings work almost everywhere. Chat apps support fewer levels or none.

AppSupportNotes
GitHub / GitLabSupportedAll six levels; every heading gets an id for # links.
DiscordDiffers#, ## and ### work in messages; -# makes small gray text.
SlackNot supportedMessages have no headings; use bold text.
ObsidianSupportedAll six levels; headings fold, and [[Note#Heading]] links to them.
NotionDiffersTyping #, ## or ### and a space makes a heading block.
RedditSupportedAll six levels work in posts and comments.

Questions and answers

How many heading levels does Markdown have?

Six: # for level 1 through ###### for level 6. They become <h1> to <h6> in HTML.

Why is my heading not working?

Put a space after the hashes (# Title, not #Title) and start the line with them. Four or more spaces before the hashes turn the line into code.

How do I link to a heading?

Use # and the heading's id: [Install](#installation). GitHub builds the id from the heading text in lowercase, with spaces turned into hyphens.

How do I make a table of contents?

List links to the headings by hand, or let the Table of Contents Generator build the list from your headings.

Should a document have only one # heading?

That is the usual convention: one level 1 heading for the title, then ## for sections. Many websites print the page title as a heading already, so documents written for them start at ##.

Can I give a heading my own id?

Not in CommonMark or on GitHub. Pandoc, Hugo and kramdown accept ## Title {#my-id}.

What is the difference between # headings and underlined headings?

For levels 1 and 2 the result is the same. Underlined headings cannot go deeper than level 2; # headings are more common and easier to spot in the source.

How do I write headings in Discord?

Start a line with #, ## or ### and a space. -# and a space makes small gray text.