Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MD018 - No Space After Hash on ATX Style Heading

Severity: Warning
Category: Headings
Auto-fix: ✓ Available

Rule Description

This rule ensures there's a space after the hash character(s) in ATX-style headings. The space improves readability and is required by many markdown parsers.

Why This Rule Exists

A space after the hash is important because:

  • Many markdown parsers require it for proper heading recognition
  • Improves readability and consistency
  • Follows CommonMark specification
  • Prevents confusion with other hash-prefixed content

Examples

❌ Incorrect (violates rule)

#Heading without space
##Another heading missing space
###Third level also needs space

✅ Correct

# Heading with proper space
## Another heading correctly formatted
### Third level with space

Configuration

This rule has no configuration options.

Automatic Fix

This rule supports automatic fixing with --fix. The fix will:

  • Add a single space after the hash character(s)
  • Preserve the heading level and content
  • Handle all heading levels (1-6)

Apply Fix

# Fix heading spacing issues
mdbook-lint lint --fix docs/

# Preview what would be fixed
mdbook-lint lint --fix --dry-run docs/

When to Disable

Consider disabling this rule if:

  • You're working with a non-standard markdown parser that doesn't require spaces
  • Your content includes hash-prefixed text that isn't meant to be headings

Disable in Config

# .mdbook-lint.toml
disabled_rules = ["MD018"]

Disable Inline

<!-- mdbook-lint-disable MD018 -->
#NoSpaceHeading
<!-- mdbook-lint-enable MD018 -->
  • MD019 - Multiple spaces after hash on ATX heading
  • MD020 - No space inside hashes on closed ATX heading
  • MD021 - Multiple spaces inside hashes on closed ATX heading
  • MD022 - Headings should be surrounded by blank lines
  • MD023 - Headings must start at the beginning of the line

References