# MD051 - Link Fragments Should Be Valid
## Description
This rule ensures that link fragments (the part after the # in a link) point to valid headings in the
document. This helps prevent broken internal links and improves navigation within Markdown documents.
## Examples
### Valid
```markdown
# Introduction
## Getting Started
[Link to Getting Started](#getting-started)
```
### Invalid
```markdown
# Introduction
## Getting Started
[Link to non-existent heading](#installation)
```
### Fixed
```markdown
# Introduction
## Getting Started
## Installation
[Link to Installation](#installation)
```
## Configuration
This rule has no configuration options.
## Special Cases
- This rule only applies to internal links with fragments (links that start with #)
- It does not apply to external links (links to other documents or websites)
- The rule checks if the fragment matches a heading in the document
- Heading IDs are generated by converting the heading text to lowercase and replacing spaces with hyphens
- Special characters in headings are removed when generating IDs
- The rule handles complex headings with punctuation, code spans, and emphasis
## Related Rules
- [MD042 - No empty links](md042.md): Ensures links have content
- [MD034 - No bare URLs](md034.md): Ensures URLs are properly formatted
- [MD039 - No space inside link text](md039.md): Ensures proper formatting of link text