How to make a Markdown table of contents with anchor links
Write a Markdown table of contents by hand with links to heading anchors, learn how GitHub builds anchor IDs, and generate one with VS Code or Pandoc.

A Markdown table of contents is a list of links to the document's own headings. Standard Markdown has no command that builds one, so you write a bulleted list where each item links to #anchor-id, and the anchor ID is the heading text in lowercase, with spaces turned into hyphens and punctuation removed. A heading written as ## Getting Started is linked as [Getting Started](#getting-started) on GitHub and in many renderers that follow the same rules.
Here is the whole pattern in one file:
# Project Guide
## Contents
- [Installation](#installation)
- [Configuration](#configuration)
- [Environment variables](#environment-variables)
- [Troubleshooting](#troubleshooting)
## Installation
## Configuration
### Environment variables
## Troubleshooting
If heading levels are new to you, the Markdown headings page explains # through ######, and the links page covers the [text](target) syntax used in every line above.
How does GitHub turn a heading into an anchor ID?
GitHub lowercases the heading, replaces each space with a hyphen, and removes other punctuation. If two headings produce the same ID, the second one gets -1, the third -2, and so on.
The full rules from GitHub's basic writing and formatting syntax guide (checked November 2026):
- Letters are converted to lowercase.
- Spaces are replaced by hyphens. Other whitespace and punctuation are removed, except hyphens and underscores already in the heading.
- Leading and trailing whitespace is removed.
- Markup formatting is removed, so
_italics_becomesitalics. - A duplicate gets a hyphen and an increasing number.
Applied to real headings, those rules give:
| Heading in the file | Link target |
|---|---|
## Getting Started |
#getting-started |
## What's new in v2.0? |
#whats-new-in-v20 |
## Q&A: setup / install |
#qa-setup--install |
## *Fast* mode |
#fast-mode |
A second ## Getting Started |
#getting-started-1 |
The double hyphen in the third row is not a typo. Both spaces around the slash become hyphens, and the slash itself is removed. GitHub also warns that if you edit a heading, or reorder headings that share an ID, the anchors change and you have to update the links that point to them.
How do you write a table of contents by hand?
Write the headings first, then build the list from them. A hand-written list works anywhere Markdown renders links, so it travels with the file.
- Finish the outline of the document so the headings are stable.
- Under the title, add a
## Contentsheading. - For each second-level heading, add a list item:
- [Heading text](#heading-id). - For third-level headings, indent the list item under its parent, so the list mirrors the structure.
- Preview the file and click every link. A link that does nothing usually has a punctuation mark left in the ID.
A few conventions keep the list readable:
- Leave out the document title (the
#heading). Readers are already at the top. - Stop at two levels. A list of every
####heading is longer than the sections it points to. - Keep the link text identical to the heading text, so readers recognize the section when they land.
Does [TOC] work in Markdown?
Not as standard Markdown. The GitHub Flavored Markdown spec (version 0.29-gfm, checked November 2026) does not define a [TOC] marker, and neither does CommonMark, which GFM extends. In tools that don't support it, [TOC] appears on the page as literal text.
Some tools do support a marker of their own:
- Python-Markdown, the library behind many static site generators, has a toc extension whose marker "defaults to
[TOC]" (checked November 2026). - Typora: its Markdown reference says to enter
[toc]and press Return. Typora then inserts a table of contents that updates as you add headings (checked November 2026).
If the file will be read on GitHub, in another editor, or by someone else's tools, write the list by hand or generate it as real links. A marker only works where the tool that understands it renders the file.
Does GitHub show a table of contents automatically?
Yes, for rendered Markdown files. GitHub's guide says it "automatically generates a table of contents that you can access by clicking the 'Outline' menu icon" on the file, and each heading in it is clickable (checked November 2026).
That covers readers browsing a README on github.com. A hand-written list is still worth adding when the file is long, when it is also read outside GitHub, or when you want readers to see the structure before they scroll.
Which tools generate a Markdown table of contents for you?
Two common options: an editor extension that writes the list into the file, and Pandoc, which adds a table of contents when it converts the file to another format.
VS Code with Markdown All in One. This extension's Marketplace page (checked November 2026) describes a Create Table of Contents command and says the table of contents "is automatically updated on file save by default." To use it:
- Install Markdown All in One from the Extensions view.
- Open your .md file and put the cursor where the list should go.
- Open the Command Palette (Cmd+Shift+P on a Mac, Ctrl+Shift+P on Windows and Linux) and run Markdown All in One: Create Table of Contents.
The setting markdown.extension.toc.levels controls which heading levels appear, and markdown.extension.toc.slugifyMode defaults to github, so the generated links follow GitHub's anchor rules.
Pandoc for Word, PDF and HTML. Pandoc's --toc option includes "an automatically generated table of contents" in the output, according to the Pandoc manual (checked November 2026). --toc-depth sets how many heading levels it lists, and the default is 3.
pandoc guide.md --toc -o guide.docx
pandoc guide.md --toc --toc-depth=2 -o guide.pdf
pandoc guide.md -s --toc -o guide.html
For HTML, the manual notes that --toc "has no effect unless -s/--standalone is used," which is why the third command has -s. For Word, Pandoc writes an instruction to create the table rather than the finished list. In our test with Pandoc 3.9, that came out as a Word field marked for updating. If the contents area looks empty when you open the file, right-click it and choose Update Field.
| Tool | Where the table of contents ends up | Updates when headings change |
|---|---|---|
| Hand-written list | In the .md file | Only when you edit it |
| Markdown All in One | In the .md file | On save, by default |
Pandoc --toc |
In the exported Word, PDF or HTML file | Each time you export |
| GitHub Outline | In GitHub's file view only | Automatically |
What if the links work on GitHub but not in another app?
Anchor rules differ between renderers. The Markdown All in One extension, for example, offers gitlab and gitea slug modes alongside github, because those sites build IDs differently. Headings with accented letters, emoji or repeated text are where the results most often split.
Two fixes:
- Test where readers will read. If the file lives on GitHub, check the links there, not only in your editor's preview.
- Set the anchor yourself. GitHub's guide allows standard HTML anchor tags, such as
<a id="setup"></a>on the line above a heading, linked as[Setup](#setup). GitHub notes that custom anchors are not included in its Outline, and some renderers strip HTML, so use this only where you need a fixed ID.
Table of contents in Noteline
Noteline, which we make, has a Table of Contents panel that lists the headings of the open note, indented by level; click one to jump to it. In the desktop app, open it with Cmd+Shift+O on a Mac or Ctrl+Shift+O on Windows and Linux. The panel is for moving around while you write and does not insert a list of links into the file, so add one by hand when readers of the .md file need it.