Markdown has no table of contents syntax. Here's how GitHub builds heading anchors, why hand-written TOC links break, and what actually works.
No. There is no [TOC], no [[TOC]], and no directive in the markdown spec. Those markers exist, but each belongs to a specific renderer, not to markdown itself.
GitHub builds an id for every markdown heading, and a TOC link works only when your #fragment matches that generated id exactly.
I ran these headings through github-slugger 2.0.0 to get the exact output rather than guess at it. The results are unintuitive enough to be worth memorising.
Before you hand-write anything, check whether you need to. On 13 April 2021 GitHub shipped automatic table of contents support: "Markdown files will now automatically…
If you've seen [TOC] work somewhere, you weren't imagining it — you were on a different renderer.
For a README that needs an inline, curated markdown TOC, generating the list beats typing it.
Profile READMEs are where this bites hardest, because they're short enough that a four-item TOC is genuinely useful and visible enough that a dead link looks careless.
The six slug rules, GitHub's built-in TOC menu, and what works for READMEs and profile pages.