Markdown Table of Contents Generator

Paste markdown headings and get an anchor-linked table of contents — GitHub-style slugs, nested by heading level

Add some # headings to generate a table of contents
Anchors are slugified the same way GitHub renders them: lowercased, punctuation stripped, spaces turned into hyphens, and a numeric suffix added for any duplicate heading text — so pasting this straight into a GitHub README's existing headings should produce working links without edits. Headings inside fenced code blocks are ignored.

Was the Markdown Table of Contents Generator helpful?

Get new tools in your inbox

About once a month, when new tools ship. No spam, one-click unsubscribe.

We store only your email to send these updates. Privacy

About this tool

The ToolNinja Markdown Table of Contents Generator scans a markdown document for headings (# through ######) and builds a nested, anchor-linked table of contents — as Markdown or as an HTML <ul> — ready to paste at the top of the same document. Anchor slugs are generated the same way GitHub renders them: lowercased, punctuation stripped, spaces turned into hyphens, with a numeric suffix appended to any duplicate heading text (so two headings both named 'Usage' become #usage and #usage-1). That matching matters — a TOC generated with a different slug algorithm than the platform actually renders will produce links that silently go nowhere. Headings inside fenced code blocks are correctly ignored, so a markdown code sample containing a line that starts with # won't be mistaken for a real heading. Everything runs 100% in your browser — your document never leaves your machine.

When to use it

  • →Adding a table of contents to a long GitHub README without hand-writing anchor links
  • →Regenerating a TOC after reordering or renaming sections in an existing document
  • →Building a TOC for a blog post or documentation page before pasting it into a CMS
  • →Checking which anchor slug a given heading will actually resolve to before linking to it from elsewhere

Tips

  • ◆Run it again after editing headings — a TOC built from an older version of the document will have stale links once heading text changes (since the slug is derived from the text itself).
  • ◆Duplicate heading text gets a -1, -2, ... suffix on its slug automatically, matching exactly how GitHub resolves the same collision.
  • ◆Switch to HTML output if you're pasting into a CMS or static site generator that doesn't render raw markdown lists.

Frequently asked questions

Why do my links not scroll to the right heading after I paste this in?

The most common cause is a slug mismatch — the platform rendering your markdown may use a slightly different slugification algorithm than GitHub's (different punctuation handling, different duplicate-suffix behavior). This tool matches GitHub's behavior specifically; if you're publishing somewhere else, check one link manually before trusting the rest.

Does this handle nested headings correctly?

Yes — the output list indents each heading according to its level (# through ######) relative to the shallowest heading in the document, so a ### under a ## is visually nested one level deeper, matching how GitHub and most markdown renderers display a proper table of contents.

Why are headings inside my code examples being skipped?

That's intentional — the tool tracks fenced code blocks (```) and ignores any line that looks like a heading while inside one, since a markdown tutorial showing "# My Heading" as a code example shouldn't itself become a table-of-contents entry.

Related tools

ToolNinja