Adding contents to a README that has grown
READMEs start short and then grow. Once a file has an install section, a usage section, configuration, troubleshooting and a changelog, readers stop scrolling and start searching. A table of contents at the top lets them jump straight to the part they need, and on GitHub each entry is a working link.
Here is a typical outline: "# Tidy", then "## Install", "### With npm", "### With Homebrew", "## Usage", "## Configuration" and "## FAQ". The single # line is the project name, so it is left out. With With subsections chosen and bullets, the result is "- [Install](#install)", then two indented entries "- [With npm](#with-npm)" and "- [With Homebrew](#with-homebrew)", then "- [Usage](#usage)", "- [Configuration](#configuration)" and "- [FAQ](#faq)". Choose Sections and the two indented lines disappear.
The anchors are where hand-written contents usually go wrong. "## What's new?" becomes #whats-new, because the apostrophe and question mark are dropped. "## API v2.0" becomes #api-v20, with the full stop gone. A heading with an emoji in it loses the emoji. If two sections are both called "## Example", the second one's anchor is #example-1. Working these out by hand is tedious; here they are made by the same rule GitHub applies.
Paste the list just under the title and the one-line description, and leave a blank line before and after it. Some people put a "## Contents" heading above it. If you do, that heading will appear in the list the next time you generate it; delete that line, or leave it, since a link to the contents is harmless.
There are limits. The list is a snapshot: rename a heading and the matching link breaks until you generate the list again. Sites that make anchors their own way, such as some documentation generators and wikis, may not match GitHub's rule, so test one link there. Headings written in raw HTML, such as <h2>Notes</h2>, are not listed. And documents over one million characters are refused.