Paste your README or any Markdown file and get a nested, linked table of contents built from its headings. Anchors follow GitHub's or GitLab's rules (duplicates included), so every link jumps to the right section, and you can insert the TOC straight into the document.
Last updated:
Advertisement
Advertisement
How to use the Markdown TOC Generator
Paste your Markdown or open a .md file. A sample README is loaded so you can see the result right away.
Choose the heading levels to include. Many READMEs skip the H1 title and list H2 and H3 sections.
Pick the anchor rules for where the file will be shown (GitHub or GitLab) and the bullet and indent style.
Copy the TOC and paste it under your title, or use Insert into document to add it between <!-- toc --> markers.
Regenerate any time: paste the updated file and insert again; the old TOC between the markers is replaced.
How heading anchors are generated
Both GitHub and GitLab turn the visible text of a heading into an id you can link to with #anchor. The steps are:
Take the rendered text only: **bold**, [links](url) and inline HTML are reduced to their text, images disappear, and `code` keeps its content.
Convert to lower case.
Remove punctuation and symbols. Letters (including accented and non-Latin letters), digits, spaces, hyphens and underscores stay.
Replace every space with a hyphen. GitLab also collapses repeated hyphens into one.
If the anchor already exists earlier in the document, add -1, -2, … in order.
Heading
GitHub anchor
GitLab anchor
## Getting Started
#getting-started
#getting-started
## What's New in v2.0?
#whats-new-in-v20
#whats-new-in-v20
## Options & Flags
#options--flags
#options-flags
## Config file (`.acmerc`)
#config-file-acmerc
#config-file-acmerc
## snake_case_names
#snake_case_names
#snake_case_names
## Usage (second time)
#usage-1
#usage-1
## Café Menü
#café-menü
#café-menü
Tips for a good README table of contents
Skip the H1. The title is already at the top of the page, so most TOCs start at H2. Going deeper than H3 usually makes the list too long to scan.
Don't skip levels. Jumping from H2 straight to H4 breaks the outline; the generator still nests the entry under its nearest parent and warns you.
Numbered TOCs need wider indents. In CommonMark a nested item must line up with the text after 1. , so numbered lists are indented at least 3 spaces even if 2 is selected.
Use the markers.<!-- toc --> and <!-- tocstop --> are the same markers used by the popular markdown-toc CLI, so the generated block can also be refreshed by that tool in a pre-commit hook.
Renaming a heading changes its anchor and breaks links from other pages. Regenerate the TOC after edits and check external links.
GitHub takes the heading's text, converts it to lower case, removes punctuation and symbols (letters, numbers, spaces, hyphens and underscores are kept), and replaces each space with a hyphen. So ## What's New? becomes #whats-new. Formatting such as bold or links is removed first and only the visible text is used.
What happens with duplicate headings?
The first heading keeps the plain anchor and later ones get -1, -2 and so on. Two sections called Usage become #usage and #usage-1. The generator numbers duplicates in document order, exactly as GitHub and GitLab do.
Are GitLab anchors different from GitHub's?
Mostly the same, with one practical difference: GitLab collapses runs of hyphens into one, so A - B becomes #a-b on GitLab but #a---b on GitHub. Pick the GitLab option if your README is hosted there.
Why are some headings missing from my TOC?
Lines starting with # inside fenced code blocks (``` or ~~~) are code, not headings, so they are skipped. Headings outside the selected depth range are left out, and a # must be followed by a space to count as a heading in CommonMark.
How do I keep the table of contents up to date?
Insert the TOC with the markers <!-- toc --> and <!-- tocstop -->. Next time, paste the edited file and click Insert into document again: everything between the markers is replaced with a fresh TOC. The markers are HTML comments, so they are invisible on GitHub.
Does GitHub generate a table of contents automatically?
GitHub shows an outline menu for README and Markdown files in the file viewer, but it does not add a TOC to the rendered page itself. Writing a TOC into the file makes it visible on the page, on npm, in editors and in exported documents.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.