Quotes, captions, names, wishes & practical how-tos

Markdown Basics

How to Write Headings in Markdown (H1 to H6)

Desk with laptop, notebook and pen, ready for learning how to write headings in markdown
Photo: www.Pixel.la Free Stock Photos, CC0, via Wikimedia Commons

How to write headings in Markdown: start a line with one to six hash signs, add a space, then type the heading text. One # gives the top-level heading (H1) and six ###### give the smallest (H6). This guide covers both heading styles, spacing rules, and how to keep your document outline clean.

Key takeaways

  • The number of hash signs sets the heading level, from H1 to H6.
  • Put a space after the hashes and a blank line before and after the heading.
  • Use one H1 per document and do not skip levels.
  • Setext headings (underlines) exist but only cover H1 and H2.

The Basic Heading Syntax

Markdown headings are called ATX headings. The line begins with hash characters, a space and then your text. The HTML a converter produces uses the matching <h1> to <h6> tags.

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

Anything beyond six hashes is not a heading, so a line starting with seven # characters is rendered as ordinary text. You can also add optional closing hashes at the end of the line (## Title ##), but they are rarely used and have no effect on the level.

How to Write Headings in Markdown Step by Step

  1. Open a blank line in your editor, leaving an empty line above it unless it is the first line of the file.
  2. Type the hash signs for the level you need: one for the page title, two for main sections, three for subsections.
  3. Press the space bar once. This space is what tells the parser the line is a heading.
  4. Type the heading text. Keep it short and descriptive.
  5. Leave a blank line after the heading, then start the paragraph or list beneath it.
  6. Preview the result to confirm the heading renders as a heading and not as plain text.

If you want to see the full set of elements around headings, our Markdown cheat sheet puts them on one page.

Source code on a laptop screen, showing how headings in markdown look as plain text
Photo: Slashme, CC0, via Wikimedia Commons (source)

Setext Headings: The Underline Style

The original Markdown specification also allows a second style. You write the text and underline it with equals signs for H1 or hyphens for H2.

Page Title
==========

Section Title
-------------

This style reads nicely in plain text, but it only reaches two levels and is easier to break by accident. A line of hyphens under a paragraph can turn that paragraph into an H2 when you meant to draw a rule. Most teams pick the hash style for everything, and that is what we recommend too.

Common Heading Mistakes and Fixes

Problem What happens Fix
#Title with no space Many parsers show it as plain text Write # Title
No blank line before the heading Some tools merge it into the previous paragraph Add an empty line above
Indented by four spaces or more Treated as a code block Start the line at the left margin
Seven or more hashes Not a heading Use six at most
Hash needed as literal text Becomes a heading Escape it: \# not a heading

The CommonMark specification documents these rules in detail, and you can read them in the CommonMark spec if you build or debug a parser.

Plan a Clear Heading Structure

Headings are not only for looks. Screen readers, search engines and tables of contents all use the heading levels to understand your document. A few habits keep that structure healthy.

  • Use a single H1 for the document title.
  • Use H2 for main sections and H3 only inside an H2.
  • Never jump from H2 straight to H4 just to get smaller text.
  • Make each heading meaningful on its own, so a reader scanning the page understands the topic.
  • Avoid bold text as a fake heading; a real heading carries structure that bold does not.

The same thinking applies in word processors. Our article on Google Docs heading styles and the document outline shows how the levels feed the outline sidebar.

Fingers typing hash signs to write headings in markdown
Photo: Cangjie6, CC BY-SA 4.0, via Wikimedia Commons (source)

Headings in Different Tools

The hash syntax is supported by nearly every Markdown editor and by platforms that render Markdown, such as code hosting sites and note apps. Some tools also generate anchor links from headings, so you can link to a section directly. How those anchors are named differs between tools, so check the documentation of the one you use.

When you move Markdown into a word processor, the hash levels usually map to the built-in Heading 1 to Heading 6 styles after conversion. If you are working with Google Docs, see how to use Markdown in Google Docs for what is supported and what is not. Menus and import options can change over time, so confirm in the app itself.

Frequently Asked Questions

How many heading levels does Markdown have?

Six. They map to the HTML heading tags H1 through H6.

Do I need a space after the hash signs?

Yes, in CommonMark and most modern parsers. Without the space, the line may not be treated as a heading.

Can I have more than one H1?

Markdown allows it, but most style guides recommend one H1 per document so the structure stays clear for readers and search engines.

Should I use hashes or underlines?

Hashes. They support all six levels, are easier to scan in source form and are less likely to be misread by a parser.

Can I put formatting inside a heading?

Usually yes. You can add emphasis, code or links inside heading text, such as ## The `main` branch, though keeping headings plain is cleaner.

Wrap-Up

Hashes, a space and a blank line are all you need. Pick one H1, nest the rest in order, and preview before you publish. If a tool behaves differently, its own Markdown documentation is the final word.

Written byEditorial Team

Part of the MarkdownToGoogleDocs editorial team, sharing copy-ready words and practical Markdown and Google Docs how-tos.