Skip to content

MD039 - Remove extra spaces in links

Aliases: no-space-in-links

What this rule does

Removes unnecessary spaces inside square brackets for link text and image descriptions.

Why this matters

  • Clean appearance: Extra spaces make links look unprofessional
  • Consistent formatting: All links should follow the same pattern
  • Better readability: Clear link boundaries improve document flow
  • Prevents broken links: Some parsers may not handle extra spaces correctly

Examples

✅ Correct

Link text directly touches the brackets:

[Visit our website](https://example.com)

![Company logo](logo.png)

[Reference link][docs]

Check the [API documentation](https://api.example.com) for details.

❌ Incorrect

Extra spaces inside square brackets:

[ Visit our website](https://example.com)

[Visit our website ](https://example.com)

[ Visit our website ](https://example.com)

![ Company logo ](logo.png)

🔧 Fixed

Spaces removed from inside brackets:

[Visit our website](https://example.com)

[Visit our website](https://example.com)

[Visit our website](https://example.com)

![Company logo](logo.png)

Configuration

This rule has no configuration options.

Automatic fixes

This rule will:

  • Remove spaces after opening brackets [
  • Remove spaces before closing brackets ]
  • Work on both regular links and image alt text
  • Handle reference-style links
  • Preserve spaces within the link text itself

Learn more