Markdown links to sections: how they work and when they hold up

How Markdown links to sections work, why heading anchors differ between renderers, what reference-style conversion changes, and when a plain-text section reference is the safer choice.

A link to a section of a Markdown document points at an anchor attached to a heading rather than at a whole page. It is one of the most useful ways to make long documents navigable. It is also one of the most fragile, because Markdown does not define how those anchors are created. This review covers what the link actually depends on, what converting it between inline and reference style changes, and when it stays usable after the text leaves the editor.

Is a section link suitable for your use?

Linking to a section is worth doing when the document will be read in a renderer you know and control. Examples include a README on a single hosting platform, a documentation site built with one tool, or notes kept in one editor. The main benefit is direct navigation: readers land on the relevant part instead of scrolling. The decisive tradeoff is that the link depends on an identifier the renderer generates from the heading text. Rename the heading, move the content to another tool, or paste it somewhere that does not render Markdown, and the link can silently stop working.

Plain text is preferable in three cases. The first is when the destination does not render Markdown, such as plain-text email, some chat tools or commit messages. The second is when the content will be published across several platforms with different anchor rules. The third is when headings are expected to change often. In those cases, a phrase such as "see the Installation section" survives where a fragment link may not.

What a section link actually changes

A section link does not change the heading's characters. The renderer reads the heading text and derives an identifier from it, often called a slug, then attaches that identifier to the HTML heading element. The link itself is an ordinary Markdown link whose target is a fragment: a hash sign followed by that identifier. The stored Markdown source keeps the heading exactly as written. Only the rendered output gains the identifier, and readers normally never see it.

## Getting Started

Jump to [Getting Started](#getting-started).

The CommonMark specification does not define heading identifiers at all. Generating them is an extension, and each renderer applies its own rules. The rules most widely described, and the ones GitHub-style rendering follows, work like this:

  • Letters are converted to lowercase.
  • Most punctuation is removed.
  • Each space becomes a hyphen.
  • If a heading repeats, the later copies get a numeric suffix such as -1 or -2.

Other tools differ in how they treat accented letters, non-Latin scripts, emoji and leading numbers. Some keep those characters, some transliterate them and some drop them.

Heading text | Fragment under GitHub-style rules | Note
Getting Started | #getting-started | Lowercased, space becomes a hyphen
FAQ & Tips | #faq--tips | The ampersand is removed, but both surrounding spaces become hyphens, giving a double hyphen
Notes (second occurrence) | #notes-1 | Duplicate headings get a numeric suffix
Café menu | Varies by renderer | Non-ASCII letters may be kept, transliterated or dropped

These examples illustrate the general algorithm. No renderer-specific test results were supplied for this review, so confirm the exact output in your target tool before relying on it. The usual way to check is to render the document and inspect the heading's identifier, or to use any copy-link control the platform provides next to the heading.

Explicit identifiers

Some Markdown dialects let you set the identifier yourself, so it no longer depends on the heading wording. Pandoc, kramdown and Markdown Extra support an attribute syntax for this. Where raw HTML is allowed, an empty anchor element placed before the heading is another option. Many hosting platforms sanitize or rewrite HTML identifiers, though, and the attribute syntax shows up as literal text in renderers that do not support it.

## Getting Started {#start}

<a id="start"></a>
## Getting Started

Converting inline links to reference style

Converting a section link from inline to reference style changes only the source layout. The link text stays in the paragraph, and the fragment moves to a definition line elsewhere in the document. When rendered, the output is the same link. The benefit is easier reading of the source and a single place to update a fragment that is reused. The link can still break in the same ways, because the anchor has not changed. Label matching in reference definitions is case-insensitive in CommonMark.

Inline:
See [the setup steps](#getting-started).

Reference style:
See [the setup steps][setup].

[setup]: #getting-started

Linking to a section in another Markdown file works the same way: add the fragment to the relative path of that file. Whether it resolves depends on the renderer handling both the path and that file's anchor rules, which is one more point to verify.

Will the link stay readable and usable after copying or sharing?

There are several limits to consider before relying on a section link outside the place where you wrote it:

  • Copying rendered text: if you copy from a rendered page and paste into a plain-text field, the destination is often lost and only the link text remains. Copying the Markdown source keeps the fragment, but the receiving tool must generate the same anchor for it to resolve.
  • Renaming headings: editing a heading changes its generated slug, and existing links fail without any warning. Explicit identifiers avoid this where they are supported. Otherwise, check links after editing headings.
  • Moving between tools: the same heading can produce different fragments in different renderers, especially with punctuation, non-ASCII text, emoji or duplicate headings.
  • Accessibility: screen readers announce the link text, not the fragment. Text such as "Getting Started section" tells a listener where the link goes, while "here" does not. Whether keyboard focus moves to the target heading after the jump depends on the browser and the page, and no assistive-technology testing was supplied for this review.
  • Search and editing: fragment links do not change how the heading text is indexed or edited. Search engines generally treat a fragment as part of the same page. No measured search impact was supplied for this review.

A plain-text equivalent is needed whenever the destination does not render Markdown, or when you cannot confirm the destination's anchor rules. Naming the section in words, such as "see Getting Started below", keeps the reference meaningful even if the link breaks. It also works well alongside the link in documents that may be exported or quoted.

Evidence gaps

No specific tool versions, renderer test results or platform documentation excerpts were supplied for this review. The anchor behavior described here reflects widely documented general rules rather than verified observations in a named environment. Before publishing, test any section link in the exact renderer, editor or platform where readers will use it.