Skip to content

MD009 - Remove trailing spaces

Aliases: no-trailing-spaces

What this rule does

Removes unnecessary spaces at the end of lines to keep your Markdown clean and consistent.

Why this matters

  • Clean diffs: Trailing spaces create noisy changes in version control
  • Parser compatibility: Some Markdown tools have issues with trailing whitespace
  • Professional quality: Clean files without hidden characters look more polished
  • File size: Removing unnecessary spaces reduces file size (slightly but it adds up!)

Examples

✅ Correct

This line ends cleanly
No extra spaces here
Perfect formatting

❌ Incorrect

This line has trailing spaces  
Extra spaces at the end 
Why are these spaces here?   

🔧 Fixed

This line ends cleanly
Extra spaces removed
Clean and tidy now

Configuration

[MD009]
br-spaces = 2                  # Number of spaces for hard line breaks (default: 2)
strict = false                 # Remove all trailing spaces, even line breaks (default: false)
list-item-empty-lines = false  # Allow trailing spaces in empty list item lines (default: false)

Automatic fixes

This rule automatically removes trailing spaces from the end of lines. When strict is false, it preserves exactly 2 spaces (or your configured br_spaces) for intentional hard line breaks.

Learn more

  • MD010 - Use spaces instead of tabs
  • MD047 - End files with a single newline