Markdown Heading Anchor Generator (GFM slug)

GitHub auto-generates anchor links for every heading in a Markdown file, with specific slug rules — lowercase, spaces to dashes, certain characters stripped, duplicate handling. This tool generates the exact anchor ID GitHub would use, so your in-page links don't break.

How to use the Markdown Heading Anchor Generator (GFM slug)

Paste your headings, one per line, keeping the leading # markers. The tool outputs the anchor ID GitHub generates for each — the fragment you put after # in a same-page link. Duplicate headings get a numeric suffix, exactly as GitHub does it.

How GitHub turns a heading into an anchor

When GitHub renders a Markdown file, it gives every heading an id so you can link straight to it with #the-heading. The slug is produced by a fixed recipe: lower-case the text, drop anything that is not a letter, number, space, or hyphen, then replace each run of spaces with a single hyphen. So “Installation & Setup” becomes installation--setup — the ampersand vanishes and the two surrounding spaces both become hyphens.

Repeated headings are disambiguated by appending -1, -2, and so on to the second and later occurrences. Getting these rules exactly right matters because a table of contents or cross-reference with the wrong slug silently links nowhere. This tool applies GitHub's GFM algorithm so the anchors you write match the ones GitHub actually emits.

Common use cases

  • Hand-written tables of contents — produce anchor links that land on the right heading.
  • Cross-references — link from one part of a README to another by its exact slug.
  • Fixing broken in-page links — find why a #anchor jumps nowhere by checking the real slug.
  • Duplicate headings — see the -1, -2 suffixes GitHub adds when titles repeat.
  • Docs tooling — pre-compute anchors when generating documentation that links into GitHub.

Frequently asked questions

How does GitHub build a heading anchor?

It lower-cases the heading, removes characters that are not letters, digits, spaces, or hyphens, then converts spaces to hyphens. Emoji and punctuation are dropped, which is why the result sometimes has fewer or doubled hyphens than you expect.

How are duplicate headings handled?

The first occurrence gets the plain slug; each repeat gets -1, -2, and so on appended in order. This tool tracks duplicates across all the headings you paste so the suffixes match GitHub.

Why does my anchor link not work?

Usually the slug is slightly off — a stripped character, an ampersand that left a double hyphen, or a missing duplicate suffix. Paste the heading here to get the exact slug GitHub uses and compare.

Do other renderers use the same rules?

Roughly, but not identically. GitLab, Bitbucket, and various static-site generators each have small differences. This tool follows GitHub Flavored Markdown, which is the most common target.
Embed this tool on your site

Free to embed, no attribution required (but appreciated). Paste this where you want the tool to appear: