Markdown Best Practices
These are the Markdown habits that keep documents readable, portable and easy to review in Git. Each one maps to a markdownlint rule, so you can check them automatically instead of by eye.
New to Markdown? Start with Markdown Basics. Setting conventions for a team? See the Markdown Style Guide.
14 rules at a glance
| # | Rule | Why | markdownlint |
|---|---|---|---|
| 1 | Start with one H1, and use only one | One clear page title. Some tools build the outline from it. | MD025, MD041 |
| 2 | Do not skip heading levels (H2 to H4) | Skipped levels break the outline for screen readers and tables of contents. | MD001 |
| 3 | Use a real heading, not bold text, for a title | Bold is not in the outline and cannot be linked to. | MD036 |
| 4 | Keep heading text unique within a page | Duplicates get numbered anchors such as #install-1. |
MD024 |
| 5 | Put a blank line around headings, lists and code fences | Some parsers need it to see the block. | MD022, MD031, MD032 |
| 6 | Use one bullet character, with consistent indentation | Mixed bullets can start a second list in CommonMark. | MD004, MD007 |
| 7 | Use fenced code blocks and give each a language | Syntax highlighting, and no ambiguity. Use text for plain output. |
MD040, MD046 |
| 8 | Write link text that describes the destination | "Click here" tells a screen reader user nothing. | MD059 |
| 9 | Give every image alt text | Screen readers and broken-image fallback. | MD045 |
| 10 | Do not leave bare URLs | A bare URL is plain text in CommonMark. Wrap it in <> or use [text](url). |
MD034 |
| 11 | Use relative links for files in the same repository | They survive forks, renamed branches and moved hosts. | link checker |
| 12 | No trailing spaces, no stacked blank lines, one final newline | Cleaner diffs, and fewer invisible line breaks. | MD009, MD012, MD047 |
| 13 | Wrap lines the same way throughout | Mixed wrapping makes diffs noisy. | MD013 |
| 14 | Limit raw HTML | Some platforms strip tags, and Markdown stops working inside an HTML block. | MD033 |
Rule IDs come from the markdownlint rules reference.
Three rules that need explaining
Rule 13: line wrapping#
In CommonMark a single newline inside a paragraph is a space, so wrapping lines at 80 characters does not change the output. It only changes the Git diff. Common choices:
- No wrapping. One paragraph per line. Simple, but a one-word edit shows the whole paragraph as changed.
- One sentence per line. An edit touches only the sentence you changed. A popular choice for docs kept in Git.
- Hard wrap at a fixed width. Fits terminals, but rewrapping after an edit creates large diffs.
Pick one for the project and do not mix them. markdownlint's MD013 checks line length and is often switched off when you do not wrap.
Rule 4 and rule 11: anchors and relative links#
Platforms such as GitHub build an anchor from each heading (## Install the app becomes #install-the-app). Renaming a heading breaks every link to it, and a repeated heading gets a number added. Check the links after you rename a heading.
For links to other files in the same repository, write [Setup](docs/setup.md) and not the full GitHub URL. Relative links keep working in forks and on other branches. Use absolute URLs where the README is shown outside the repository, and check how that site resolves relative paths.
Rule 12: trailing spaces#
Two trailing spaces make a hard line break, but they are invisible and many editors remove them. Put \ at the end of the line instead. By default markdownlint allows exactly two trailing spaces, so set "MD009": { "br_spaces": 0 } (see the config below) and it flags those too. Every other trailing space is almost always a mistake.
Before and after
Before
# Setup
### Install
**Notes**
* Run `npm install`
- Then start the app
See [here](docs/setup.md) or https://example.com

Running markdownlint on this block reports 12 errors:
| Problem | Rule |
|---|---|
| No blank line after the H1 and around the H3 | MD022 |
| H1 jumps to H3 | MD001 |
**Notes** used as a heading |
MD036 |
| No blank lines around the list | MD032 |
* and - mixed in one list |
MD004 |
| Bare URL | MD034 |
| Link text "here" | MD059 |
| Image with no alt text | MD045 |
After
# Setup
## Install
### Notes
- Run `npm install`
- Then start the app
See the [setup guide](docs/setup.md) or <https://example.com>.

The same linter reports 0 errors on this version.
Check it automatically
markdownlint runs every rule above. Add a .markdownlint.json to the project:
{
"default": true,
"MD013": false,
"MD009": { "br_spaces": 0 },
"MD033": { "allowed_elements": ["details", "summary", "kbd"] }
}
This turns on all rules, turns off the line-length rule, flags every trailing space (including a two-space line break), and allows three HTML tags. Run it:
npx markdownlint-cli2 "**/*.md"
Other checks worth adding:
- Formatting:
npx prettier --check "**/*.md"flags files that Prettier would reformat. - Links:
npx markdown-link-check README.mdtests every link in a file. You can also paste a document into our link checker tool: Markdown Link Checker. - Tables: paste messy tables into the table formatter.
In VS Code, the markdownlint extension shows the same warnings as you type.
Frequently Asked Questions
- 1
How many H1 headings should a Markdown page have?
One. Markdown does not forbid more, but a single H1 keeps the outline clean (rule
MD025). Some static site generators print the page title from front matter, so the body then starts at H2. - 2
Should I wrap Markdown lines at 80 characters?
It is optional. Wrapping does not change the rendered output. Pick one style and keep it. One sentence per line gives the smallest Git diffs.
- 3
Which tool lints Markdown?
markdownlint is the most used one. It has a command-line version and a VS Code extension. remark-lint is an alternative, and Prettier formats Markdown but does not enforce these rules.
- 4
Should I use HTML inside Markdown?
Only when Markdown cannot do it. Some platforms strip tags, and Markdown inside an HTML block may not render. If you need
<details>or<kbd>, allow those tags in the lint config. See Markdown and HTML. - 5
Do these rules work everywhere?
They are portable, but tables, task lists and footnotes depend on the platform. See the Markdown Reference and the CommonMark Guide.
