MD012 - Remove multiple blank lines¶
Aliases: no-multiple-blanks
What this rule does¶
Reduces multiple consecutive blank lines to just one, keeping your documents clean and consistent.
Why this matters¶
- Readability: Too many blank lines make documents feel disconnected and harder to follow
- File size: Extra blank lines waste space without adding value
- Professional appearance: Clean spacing looks polished and intentional
- Consistency: Standard spacing makes documents easier to maintain
Examples¶
✅ Correct¶
# Chapter 1
This is the introduction paragraph.
## Section 1.1
Content for this section.
## Section 1.2
More content here.
❌ Incorrect¶
# Chapter 1
This is the introduction paragraph.
## Section 1.1
Content for this section.
## Section 1.2
More content here.
🔧 Fixed¶
# Chapter 1
This is the introduction paragraph.
## Section 1.1
Content for this section.
## Section 1.2
More content here.
Configuration¶
Heading awareness¶
MD012 reads MD022's lines-above and lines-below configuration to determine how many blank lines are allowed adjacent to headings. This prevents MD012 from flagging blank lines that MD022 requires.
For example, with lines-above = 2, you need two blank lines before each heading — MD012 will allow up to 2 blank lines above headings while still flagging excess elsewhere:
The two blank lines before ## Section are allowed by MD012 because MD022 requires them. Multiple blank lines between non-heading content are still flagged normally.
If MD022 is disabled, MD012 enforces its own maximum everywhere without any special heading treatment. If MD022 uses lines-above = -1 (unlimited), MD012 will not flag any blank lines above headings.
Automatic fixes¶
This rule automatically removes excess blank lines. Near headings, blanks are capped at the limit derived from MD022's configuration. Between non-heading content, blanks are capped at MD012's own maximum (default: 1).
Learn more¶
- Paragraphs in Markdown - How to use blank lines effectively
- CommonMark specification - Technical details about blank lines