Markdown TOC Generator
Table of contents for Markdown with GitHub-style anchor links.
About this tool
Paste Markdown and get a nested table of contents with working links to each heading. Choose which heading levels to include, bullets or numbers, and whether to link. Copy just the TOC, or copy the whole document with the TOC inserted between <!-- toc --> markers.
How the anchor links are made
GitHub, and most Markdown renderers that copy it, give every heading an id so you can link to it with #anchor. The rule is to lowercase the text, remove punctuation except hyphens and underscores, and turn spaces into hyphens, so "FAQ & troubleshooting" becomes #faq--troubleshooting and "Configure `.env`" becomes #configure-env. When two headings have the same text, the second gets -1, the third -2 and so on. This generator applies the same rules, reads both # headings and underlined (setext) headings, and ignores lines inside fenced code blocks, so a # comment in a bash example isn't mistaken for a heading. The usual choice is H2โH3, which leaves out the page title and very deep sections. Inserting between <!-- toc --> and <!-- tocstop --> markers lets you regenerate the TOC whenever headings change. Honest limits: GitLab, Bitbucket, Docusaurus and other platforms generate anchors slightly differently, especially for emoji and non-Latin characters, so check a couple of links after publishing. The Markdown preview, the README generator and the Markdown table generator are related, and What Markdown is, the syntax that matters, and where it works covers the syntax.
Frequently asked questions
How do I add a table of contents to a GitHub README?
Paste the README here, copy the TOC and place it near the top. The links use GitHub's anchor rules.
How are duplicate headings handled?
Like GitHub: the second gets -1, the third -2, and so on.
Does it include headings inside code blocks?
No. Lines inside fenced code blocks are ignored.
Is my data uploaded?
No. Everything runs in your browser and nothing is stored or sent.