markdownlint/doc/md051.md

36 lines
967 B
Markdown
Raw Normal View History

# `MD051` - Link fragments should be valid
Tags: `links`
Aliases: `link-fragments`
This rule is triggered when a link fragment does not correspond to a heading
in the document:
```markdown
# Title
[Link](#fragment)
```
To fix the issue, change the fragment to reference an existing heading:
```markdown
[Link](#title)
```
Alternatively, an HTML `a` tag with an `id` (or a `name`) attribute defines a
valid anchor:
```markdown
<a id="fragment"></a>
```
Some platforms (e.g., [GitHub][github-section-links]) automatically create HTML
anchors for every heading. This makes it easy to link to different sections in
a document. These internal links can break over time as headings are renamed.
Note: Creating anchors for headings is not part of the CommonMark specification.
[github-section-links]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#section-links