Generate a Markdown Table of Contents with Links
How Markdown table of contents generators turn headings into anchor links, where those links break, and when a plain-text outline is the better choice.
A Markdown table of contents (TOC) is a list of links that point to the headings in the same document. You can write one by hand, but most people use a generator, such as a command-line script, an editor extension or a feature built into the platform that renders the file. This review explains what generation changes in your document, where linked TOCs hold up, where they fail, and when a plain list of section names is the safer option.
Is a generated, linked TOC suitable for your document?
For long Markdown files that will be read on the platform where they are rendered, a generated TOC is usually worth it. A README, project documentation or a long guide all fit that description. The main benefit is navigation: readers can see the structure at a glance and jump straight to a section, and you don't have to type anchor links yourself.
The main tradeoff is that the links depend on the renderer. Every link targets an anchor ID that the rendering platform derives from the heading text. Markdown itself does not standardize how those IDs are built, so a TOC that works on one platform can contain dead links on another. A TOC also goes stale whenever headings are renamed, added or removed, unless you regenerate it.
A plain-text outline, with no links, is the better choice in these cases:
- The content will be pasted into a destination that does not render Markdown, such as plain-text email, many chat tools or a form field.
- The document is short enough that a reader can scroll through it easily.
- You cannot confirm which renderer will display the file, or the file will be published on several platforms with different anchor rules.
- The platform already generates its own outline or navigation, and a second, hand-maintained TOC would only duplicate it.
What a TOC generator actually changes
In this context, "transformation" does not mean reversing, mirroring or restyling text. A TOC generator reads your headings and writes new Markdown that refers to them. The heading text stays the same. The generator adds a block of list items, and each item is a link whose target is a fragment such as #getting-started.
The anchors themselves are usually not stored in your file. The rendering platform creates them when it converts Markdown to HTML, by assigning an id attribute to each heading. The generator has to predict those IDs correctly, which is why generators usually let you choose a slug style for a particular platform. Some setups instead use a marker that the renderer expands into a TOC at display time. In that case nothing is written into the source file, and the TOC exists only in the rendered output.
The example below uses the slug rules that GitHub documents for its rendered Markdown:
• Letters are lowercased.
• Most punctuation is removed.
• Spaces become hyphens.
• Repeated headings get a numeric suffix.
Other renderers may produce different IDs for the same headings.
# Project Guide
<!-- toc -->
- [Getting Started](#getting-started)
- [Step 2: Configure](#step-2-configure)
- [FAQ & Troubleshooting](#faq--troubleshooting)
- [Examples](#examples)
- [Examples](#examples-1)
<!-- tocstop -->
## Getting Started
## Step 2: Configure
## FAQ & Troubleshooting
## Examples
## Examples
Each line of the example shows one slug rule:
• "Step 2: Configure" loses its colon.
• "FAQ & Troubleshooting" ends up with a double hyphen. The ampersand is removed, but the spaces on either side of it each become a hyphen.
• The second "Examples" heading gets a "-1" suffix so it can be targeted separately.
The comment markers around the list are a common convention that lets a generator find and replace its previous output. The markers are not part of Markdown, and their exact form depends on the tool.
Headings with non-ASCII text are where generators and renderers are most likely to disagree:
• Accented letters may be kept as they are, percent-encoded in the link or transliterated, depending on the tool.
• Emoji may be dropped or kept.
• A heading that consists only of emoji or symbols can end up with an empty or purely numeric slug.
A single visible character can consist of several code points, such as a letter plus a combining accent or an emoji sequence. A slugger that handles code points one at a time can therefore keep part of a character and drop the rest. No tool-specific test results were supplied for this review, so check headings like these in your actual destination rather than assuming they work.
Ways to produce a TOC, and what each depends on
| Approach | What ends up in the source file | Main dependency | Typical failure |
| Hand-written links | A list of links you type and maintain | Knowing the renderer's slug rules | Typos and stale links after edits |
| Generator script or editor extension | A list of links, often between markers | The slug style matching the target platform | Wrong anchors when the file moves to another platform |
| Renderer-expanded marker | Only a placeholder token | Support from the specific renderer | The token shows up as literal text where it is not supported |
| Platform-provided outline | Nothing | The platform's own interface | No TOC when the file is viewed or exported elsewhere |
Will the TOC still work after copying or sharing?
It depends on what is being copied and where it goes:
• Copying the Markdown source to another Markdown platform keeps the link syntax intact. The links work only if that platform generates the same heading IDs.
• Copying the rendered TOC from a browser into a word processor or email usually carries the link text and may carry the fragment links. Whether those links point anywhere useful depends on the destination.
• Pasting into a plain-text destination strips the links completely, leaving either the bare section names or the raw bracket-and-parenthesis syntax. The raw syntax is harder to read than a simple outline.
Editing affects the TOC too. Renaming a heading changes its anchor, so the TOC entry for it, and any links from other documents that pointed to the old anchor, will silently break. If other pages deep-link into your sections, keep heading wording stable or check those links after edits. Regenerating the TOC fixes its own entries but does not update links from elsewhere.
For accessibility, a TOC written as a Markdown list renders as an HTML list of links. That structure generally helps screen-reader and keyboard users move through a long page. Three practices support this:
• Keep each entry's link text identical to its heading, so readers who jump there land on the wording they expect.
• Avoid emoji or decorative symbols in headings, because assistive technology may read them aloud in a distracting way.
• Make sure heading levels follow a logical hierarchy, since the TOC simply reflects that hierarchy.
No assistive-technology testing was supplied for this review, so these are general principles rather than verified results for a particular screen reader.
For search, a TOC adds a short block of internal links and repeats the heading text. It does not change the headings themselves. The evidence supplied for this review does not include any measured effect on search visibility, and none is claimed here.
Practical checklist
- Identify the renderer that will display the file and choose the matching slug style.
- Render the document and click every TOC link, especially headings with punctuation, duplicates, accents or emoji.
- Use regeneration markers or a renderer-supported placeholder so the TOC can be refreshed after edits.
- Re-check the links after renaming headings or moving the file to another platform.
- Provide a plain-text outline when the content is headed somewhere that does not render Markdown.
Gaps in this review
No specific generators, versions or platform test results were provided, so this review does not rank tools or confirm how any one of them handles edge cases. The slug example follows GitHub's published behavior and should not be assumed to hold on other platforms. Before relying on a generated TOC, test it on the exact platform where readers will use it.