Markdown linting with markdownlint: rules and setup
Lint Markdown with markdownlint-cli2: the rules that catch real problems, a config file to start from, inline disable comments, and running it in CI.

Markdown linting is running a tool over your .md files that flags structural and style problems, such as a skipped heading level, a code block with no language, trailing spaces or a bare URL, and fixes the ones it safely can. The most widely used linter is markdownlint, which has about fifty numbered rules (MD001, MD022 and so on) and runs from the command line through markdownlint-cli2, in VS Code through an extension, and in CI on every pull request. Start with its defaults, turn off the two or three rules that fight your house style, and let it run automatically.
This guide covers the commands, a starting configuration, the rules worth knowing by number, and when to reach for a different linter. Commands and rule names are from the markdownlint and markdownlint-cli2 documentation, checked November 2026.
Why lint Markdown at all?
Markdown renders something even when the source is sloppy, which is why problems slip through. A linter catches the ones that matter to readers and tools:
- Broken structure. A page that jumps from
#to###produces a broken outline, sidebar or table of contents in every docs generator. - Unreadable code. A fenced block without a language gets no highlighting, and some generators style it differently.
- Rendering surprises. A list with no blank line before it can merge into the paragraph above in some renderers.
- Noisy diffs. Trailing spaces, mixed list markers and hard tabs create changes in pull requests that have nothing to do with the content.
- Accessibility gaps. Images with no alt text.
On a team, linting also ends style discussions in review: the rule decides, and the reviewer can focus on what the text says.
How do you run markdownlint from the command line?
Install markdownlint-cli2 and point it at a glob. It lints every matching file and prints one line per problem.
npm install markdownlint-cli2 --save-dev
npx markdownlint-cli2 "**/*.md" "#node_modules"
The # prefix excludes a path, so "#node_modules" skips installed packages. Each problem is reported with the file, line, rule and a message, roughly like this:
docs/install.md:14 MD001/heading-increment Heading levels should only increment by one level at a time [Expected: h2; Actual: h3]
docs/install.md:31 MD040/fenced-code-language Fenced code blocks should have a language specified
README.md:7:81 MD013/line-length Line length [Expected: 80; Actual: 112]
Add --fix to correct every fixable problem in place, then review the diff:
npx markdownlint-cli2 --fix "**/*.md" "#node_modules"
markdownlint-cli2 is also available through Homebrew (brew install markdownlint-cli2) and as a Docker image. The older markdownlint-cli package is a separate project with a different command name and options.
Which markdownlint rules matter most?
Every rule has a number and a readable alias, and you can use either in configuration. These are the ones that fire most often in real repositories:
| Rule | Alias | What it flags | Auto-fix |
|---|---|---|---|
| MD001 | heading-increment | Skipping a heading level, e.g. ## to #### |
No |
| MD004 | ul-style | Mixed -, * and + bullets |
Yes |
| MD009 | no-trailing-spaces | Spaces at the end of a line | Yes |
| MD012 | no-multiple-blanks | Two or more blank lines in a row | Yes |
| MD013 | line-length | Lines over 80 characters | No |
| MD022 | blanks-around-headings | Headings without a blank line around them | Yes |
| MD024 | no-duplicate-heading | Two headings with the same text | No |
| MD025 | single-h1 | More than one top-level heading | No |
| MD031 | blanks-around-fences | Code fences without blank lines around them | Yes |
| MD032 | blanks-around-lists | Lists without blank lines around them | Yes |
| MD033 | no-inline-html | Any HTML tag in the Markdown | No |
| MD034 | no-bare-urls | A URL not wrapped in <> or a link |
Yes |
| MD040 | fenced-code-language | A code fence with no language | No |
| MD041 | first-line-heading | A file that does not start with a top-level heading | No |
| MD045 | no-alt-text | An image with empty alt text | No |
| MD047 | single-trailing-newline | A file that does not end with one newline | Yes |
| MD051 | link-fragments | A #anchor link to a heading that does not exist |
Yes |
| MD056 | table-column-count | Table rows with the wrong number of cells | No |
MD001 and MD025 together enforce a clean outline: one # title, then levels in order. The headings page covers the syntax they check.
What configuration should you start with?
Start with every rule on and turn off or tune only what conflicts with how you actually write. Save this as .markdownlint.jsonc in the repository root:
{
// Every rule on by default
"default": true,
// Long lines are fine; editors wrap them and diffs stay readable
"MD013": false,
// Allow a few HTML elements that Markdown cannot express
"MD033": { "allowed_elements": ["details", "summary", "kbd", "br"] },
// Repeated headings are fine under different parents,
// e.g. "### Added" under each version in a changelog
"MD024": { "siblings_only": true }
}
The default key sets the starting state for all rules, and the keys after it override single rules. markdownlint-cli2 also reads .markdownlint.json, .markdownlint.yaml and .markdownlint-cli2.jsonc; the last one can hold the file globs and ignores as well as the rules, so the command line can shrink to npx markdownlint-cli2.
Rules teams commonly relax:
- MD013, line length. Many teams write one paragraph per line. Turn it off, or set
"line_length"higher and exclude tables and code blocks. - MD033, inline HTML. Allow the specific elements you use rather than turning the rule off.
- MD024, duplicate headings.
siblings_onlyfixes the false positives in a changelog while still catching real duplicates. - MD041, first line heading. A
title:field in front matter satisfies it by default, and thefront_matter_titleoption changes that pattern. Pages that start with other content fail it, so some teams turn it off in content folders.
How do you disable a rule for one spot?
Use an HTML comment in the file. It does not render, and it documents the exception where it happens.
<!-- markdownlint-disable-next-line MD033 -->
<img src="diagram.png" width="480" alt="Request flow from client to API">
<!-- markdownlint-disable MD013 -->
| A very wide table that has to stay on one line per row | ... |
<!-- markdownlint-enable MD013 -->
<!-- markdownlint-disable-file MD041 --> turns a rule off for the whole file. If you find yourself writing the same exception in many files, change the config instead.
How do you run markdownlint in an editor and in CI?
Run it in both: the editor catches problems as you type, and CI makes sure nothing unlinted is merged.
In VS Code, install the markdownlint extension by David Anson. It reads the same config file and underlines problems as you type. To fix on save, add this to your settings:
"editor.codeActionsOnSave": {
"source.fixAll.markdownlint": "explicit"
}
In CI, add one step to the workflow that already runs on pull requests:
- run: npx markdownlint-cli2 "**/*.md" "#node_modules"
A non-zero exit code fails the job when any rule is broken. More on wiring docs checks into pull requests is in docs as code, and the VS Code side of Markdown work is covered in Markdown in VS Code.
What other Markdown linters are there?
markdownlint checks structure. Other tools cover formatting, prose and links, and they combine well:
| Tool | Checks | Use it for |
|---|---|---|
| markdownlint | Structure and style rules | The baseline for any repository |
| Prettier | Reformats Markdown consistently | Teams that already format code with Prettier |
| remark-lint | Plugin-based rules on the remark parser | Projects already using remark or MDX |
| Vale | Prose: terms, tone, wording rules | Docs teams with a style guide |
| lychee, markdown-link-check | Dead links | Any docs with external links |
If you run Prettier and markdownlint together, let Prettier format first and turn off any markdownlint rule that disagrees with its output, so the two never fight over the same lines.
Writing lint-clean Markdown in Noteline
Noteline, which we make, does not include a linter, so keep markdownlint in your editor or CI. It helps with the habits the rules check: Markdown Source (Cmd+Shift+M on a Mac, Ctrl+Shift+M on Windows and Linux) shows blank lines and list markers exactly as saved, the Table of Contents panel (Cmd+Shift+O or Ctrl+Shift+O) makes a skipped heading level easy to spot, and the language picker on a code block reads Plain Text when no language is set, so a missing one stands out.