A table of contents in Markdown, by hand or made for you
Checked November 2026 against GitHub's formatting docs, Typora's Markdown reference, Obsidian's Outline help and the pandoc manual. I make Coffee, so weigh what I say about it. Coffee isn't affiliated with any of them.
Markdown has no table of contents of its own. There's no tag for one in CommonMark, so every table of contents you've seen in a Markdown file was either written by hand as a list of links, or drawn by the app showing the file.
Which one you want depends on where the file ends up. A list of links works everywhere. A [TOC] line is tidier but only means something in apps that read it. And if the file becomes a PDF or a web page, the converter can make the contents for you.
By hand: a list of links to headings
Most Markdown tools give each heading an anchor you can link to with #. On GitHub, the docs say the anchor is the heading in lower case, with spaces turned into hyphens and punctuation taken out. So a contents list looks like this:
## Contents
- [Flights](#flights)
- [Where to stay](#where-to-stay)
- [Day trips](#day-trips)
## Flights
...
## Where to stay
...
## Day trips
Indent an item to show a heading under another one. The catch is upkeep: rename a heading and its anchor changes, so the link in the list breaks. GitHub's docs warn about exactly that. Two headings with the same words get -1, -2 and so on added to the second and later ones.
This form has one real strength: it's plain links, so it works in every viewer, every export and every app that will ever open the file.
A [TOC] line your editor fills in
Several editors read a line holding only [TOC] and draw the headings there, kept up to date as you write. Typora does it when you type [toc] and press Return. Coffee does it on the Mac with [TOC] on a line of its own:
# Lisbon in May
[TOC]
## Flights
## Where to stay
## Day trips
Under the line, Coffee lists Flights, Where to stay and Day trips, and a click on one goes there. Add or rename a heading and the list follows. The file keeps the line exactly as written, so another app shows the word [TOC], or nothing at all, and nothing breaks. It's in Coffee's help on tables of contents.
That's the trade: no upkeep, but the contents only exist where the app understands the line. GitHub, for one, doesn't draw [TOC]. It does something better for its own pages, below.
Contents your app shows beside the note
Sometimes you don't need contents in the file at all, only a way to get around a long one.
- GitHub makes a table of contents for any file with two or more headings, behind the Outline button at the top of the file, according to its docs.
- Obsidian has a core Outline plugin that lists the open note's headings in a side panel. A click jumps there, and dragging a heading moves its section.
- Coffee shows the outline as small marks in the margin, and dragging a heading there moves the whole section. The Outline in the sidebar plugin lists the headings in the sidebar instead, and marks one that skips a level.
Made when you export
If the Markdown is a source for something else, let the converter build the contents. Pandoc adds one with --toc, as long as you also pass -s for a standalone file, and --toc-depth sets how many heading levels it includes. Three is the default.
pandoc notes.md -s --toc -o notes.html
The guide to Markdown to HTML on a Mac covers the rest of that command, and Markdown to PDF the PDF side.
Which to use
- The file is read on GitHub or in many apps: a list of links, or nothing and let GitHub's outline do it.
- It's your own long note: a
[TOC]line in an editor that reads it, or the editor's outline. - It becomes a document or a site: the converter's option.
Whichever you pick, headings that go in order help. A jump from ## to #### makes any contents look odd. Coffee's Check document finds skipped headings and can fix them. For the heading syntax itself, see the Markdown cheat sheet.
Questions
Does Markdown have a table of contents tag?
No. Neither CommonMark nor GitHub Flavored Markdown defines one. [TOC] is a convention that some editors, such as Typora and Coffee, read and draw.
Why did my table of contents link stop working?
The heading probably changed. A heading's anchor is made from its words, so renaming it changes the anchor and breaks links written by hand.
Does GitHub show [TOC]?
No. GitHub makes its own table of contents for a file with two or more headings, from the Outline button at the top of the file.
Does Coffee change the [TOC] line in my file?
No. It draws the headings under the line, and the file keeps the line exactly as you wrote it.
[TOC] and the margin outline are in Coffee on the Mac, on macOS 15 or later, and Coffee for iPhone and iPad opens the same notes. It's free for 14 days without a card, then €3 a month, €29 a year, or €79 once with two years of updates.