How to Add a Table of Contents to a Markdown README
Create a linked, nested table of contents for a README or guide, choose the right anchor style for GitHub or GitLab, and keep it up to date with markers.

How to Add a Table of Contents to a Markdown README
A long README is a wall of text until it has a table of contents. A short linked list at the top lets readers see what the document covers and jump straight to installation, configuration or troubleshooting. Writing that list by hand is tedious and, worse, it goes out of date as soon as somebody renames a section. This guide explains how heading links work and how to generate and maintain a TOC with the free Markdown Table of Contents Generator.
How heading links work
When GitHub, GitLab or a static site renders Markdown, it gives every heading an anchor, a short identifier you can link to with a hash sign. The anchor is calculated from the heading text. On GitHub the text is lowercased, punctuation other than hyphens and underscores is dropped, and each space becomes a hyphen. A heading called Install & Run therefore becomes install--run, with two hyphens because the ampersand disappeared between two spaces. If two headings have the same text, the second gets -1 at the end.
Other platforms differ. GitLab merges the double hyphen into one, Bitbucket puts a prefix in front, and many site generators strip accents to produce plain ASCII. A TOC built with the wrong rules looks fine but its links lead nowhere, so the first decision is the anchor style.
Deciding what to include
Most documents have one H1, the title, and the contents list starts at the H2 sections below it. Including H3 as a second level is usually helpful; going deeper makes the list longer than the sections it describes. Leave out sections that every reader skips, such as License or Changelog, to keep the list focused.
Numbered lists suit manuals and specifications where people refer to section numbers in conversation. Bullets suit READMEs.
Step by step
- Paste your Markdown into the Document box, or drop a file.
- Choose the anchor style for the place where the document is read.
- Set From level and To level, and decide whether to skip the title.
- Choose bullets or numbers, the indent width and any headings to leave out.
- Check the outline. It lists every heading with its level, anchor and line number, and warns when the structure jumps a level, for example from H2 straight to H4.
- Press Insert into document. The TOC is placed under the title, between two invisible comment markers.
- Download the updated file, or copy just the TOC.
Keeping it up to date
The markers are the key to maintenance. After you add or rename sections, open the file again and press Update TOC in document. Only the lines between the markers are replaced, so the rest of the file stays exactly as it was. The marker format is shared with popular editor extensions, so colleagues who prefer those tools can refresh the same TOC.
For a docs folder with many pages, drop all files at once. Each one receives its own TOC with the same options, and they download together as a ZIP.
Tips for headings that link well
Short, distinct headings make the best anchors, and they also read better in the list itself. Avoid emoji and special characters, which different renderers treat differently. Avoid repeating the same heading text in one file. And remember that renaming a heading changes its anchor, so links from other pages may need updating too; a link checker catches those.
Privacy
The generator runs in your browser. Your document and options are kept in local storage on this device and are not uploaded.



