How to Structure a Table of Contents for Long Blog Posts

Key takeaway
A good table of contents mirrors your H2 headings exactly, uses jump links with clean URL fragments (like #pricing-models), and stays under 9-10 items even on a 4,000-word post — anything deeper becomes a navigation problem instead of a solution. It sits right after the intro, before the first H2, and every link in it should resolve to a visible on-page anchor, not a dead placeholder.
Key takeaways
- Match every TOC entry word-for-word to its H2/H3 heading — mismatched text breaks both reader trust and AI citation accuracy.
- Keep top-level entries to 5-9 items; nest H3s only if a section genuinely has sub-parts a reader would search for separately.
- Use real
idattributes and#fragmentlinks, not JavaScript scroll handlers, so the TOC still works if JS fails to load.
Why the TOC Matters More Than It Looks
A table of contents does two jobs that have nothing to do with each other, and most people only design for one. The first job is reader navigation — letting someone skip to the pricing section of a 3,000-word comparison post. The second job, which has gotten more important since AI answer engines started summarizing pages, is giving a crawler a pre-built map of your document's claims.
When Perplexity or an AI Overview pulls a snippet from your post, it's usually anchoring to a specific H2 or H3, not the whole page. A clean, accurate TOC is the clearest signal you can give about where each distinct claim lives. Pages where the TOC text doesn't match the actual heading text create a subtle mismatch: the crawler indexed "Pricing Tiers Explained" from your TOC, but the heading on the page says "What Does It Cost?" — now the citation points to the wrong anchor, or gets skipped entirely in favor of a competitor's cleaner structure.
Where to Place It and What to Include
Put the TOC immediately after your opening paragraph(s), before the first H2. Readers decide whether to commit to a long post in the first 10-15 seconds, and a visible map of what's coming reduces bounce — this lines up with long-documented scanning behavior where people read web pages in an F-shaped pattern, skimming headings down the left side rather than reading linearly, as described in Nielsen Norman Group's eye-tracking research.
Practical rule for what to include:
- List every H2. Always.
- List an H3 only if it answers a question someone might search independently (e.g., "Refund Policy for Annual Plans" under a broader "Pricing" H2).
- Skip H3s that are purely transitional or structural ("Example," "Summary") — they add clutter without adding findability.
- Don't include the intro or FAQ section as TOC entries if they're short; the FAQ can stay off the TOC since it already gets its own rich result treatment in search.
If you're deciding how deep a post needs to go at all, that's really a question of how many distinct subtopics you're covering — which ties directly into how many keywords a single post should target. A post built around one keyword rarely needs more than 5-6 TOC entries; a post covering an umbrella topic with several related searches often needs the full 9.
The Technical Part Most People Get Wrong
A TOC is only as good as its links, and this is where automated content pipelines quietly fail. Three specific failure modes, in order of how often we see them:
- ID collisions. Two headings generate the same slugified ID (e.g., two H2s both titled "Getting Started" both become
#getting-started), so the second link just scrolls to the first instance. Fix it by appending a number or making headings unique. - IDs that don't match the visible heading text. Some CMS platforms auto-generate IDs from an earlier draft of the heading. You rename the H2, the ID stays stale, and the TOC link now points to nothing — the browser just stays put. Always regenerate anchors after final edits, not before.
- JavaScript-dependent smooth scroll with no native fallback. If your TOC relies entirely on an onClick handler, it breaks for any crawler or browser that doesn't execute that script, and it breaks accessibility for keyboard navigation. Use real anchor tags (
<a href="#section-id">) as the baseline; add smooth-scroll as a progressive enhancement on top, not the only mechanism.
The accessibility angle isn't a side note — it's a published standard. The W3C's Web Content Accessibility Guidelines specifically call for mechanisms to bypass repeated blocks of content, and a working in-page TOC is one of the simplest ways to satisfy that for long-form content.
How This Changes When an AI Writes the First Draft
If you're generating long posts with an AI writing agent — which is the default for most solo founders now — the TOC needs to be built from the final heading structure, not planned upfront and left static. Here's the actual failure we see constantly: someone writes a brief that specifies an outline, the agent drafts the post, but during drafting it merges two sections or splits one into two, and the TOC (generated from the original outline) no longer matches the live headings.
The fix isn't a prompting trick, it's a pipeline order: generate the full draft first, extract headings from the finished HTML, then build the TOC programmatically from that extraction. Any TOC that's hand-typed separately from the content it describes will drift out of sync the first time someone edits a heading later. If you're setting up briefs for an AI agent in the first place, it's worth specifying this heading-extraction step explicitly — see how to write a content brief an AI writing agent can actually follow for the broader version of this problem.
Should the TOC Be Collapsible?
For posts under about 1,500 words, skip the TOC entirely — it adds visual weight without enough content to justify navigating around. Past that, a collapsed-by-default TOC (one click to expand) works better on mobile because it doesn't push the actual content below the fold on a small screen. On desktop, an always-visible sticky sidebar TOC works if your layout supports it, since it keeps navigation available without taking a click.
One thing to test rather than assume: whether a sticky TOC increases or decreases time-on-page. We've seen it go either way depending on the audience — technical readers tend to use it to jump directly to the one section they came for and then leave, which looks like a worse engagement number but is actually the TOC doing its job correctly. If you're tracking this in Google Analytics 4, look at scroll-depth and section-level engagement events rather than raw time-on-page, since a fast, successful TOC-assisted visit can look identical to a bounce in aggregate metrics.
Does a TOC Actually Help SEO?
Not through rankings directly — Google has never confirmed TOC markup as a ranking factor — but it affects two things that do influence SEO outcomes. First, internal jump-link structures can surface as "jump to" links directly in Google's search results for well-structured pages, which Google's own documentation on page experience touches on as a feature tied to clear heading hierarchy and anchor markup. Second, a TOC reduces pogo-sticking (someone clicking back to search results within seconds) because readers who find their answer section via the TOC stay on the page rather than bailing when the intro doesn't immediately satisfy them.
If you're repurposing sections of a long post later — turning one deep H2 into a standalone resource — a clean TOC structure makes that extraction trivial, because each section is already a self-contained, labeled unit. That's exactly the prep work behind building a lead magnet from an existing blog post: the TOC essentially pre-segments the content for you.
A Quick Structural Checklist
- TOC appears after the intro paragraph(s), before the first H2
- Every H2 is listed; H3s only when independently searchable
- 5-9 top-level items for most posts; more than 10 usually means the post should be split into two
- Anchor text matches heading text exactly, character for character
- IDs are unique, stable, and regenerated after final edits
- Native
<a href="#id">links work without JavaScript - Collapsible on mobile, optional sticky sidebar on desktop
Frequently Asked Questions
Q: Does every long blog post need a table of contents?
Only past roughly 1,500 words. Below that, a TOC adds visual clutter without enough content to justify jumping around, and readers will just scroll normally.
Q: How many sections should be in a table of contents?
Keep it to 5-9 top-level items. If you're listing more than 10, the post likely covers too many distinct subtopics and should probably be split into two articles.
Q: Should table of contents links use hash anchors or full URLs?
Use hash anchors (#section-id) pointing to real id attributes on your headings. They work without JavaScript, support browser back/forward navigation, and are what both screen readers and search engines expect.
Q: Can a table of contents help a page get cited by AI answer engines?
Yes, indirectly — when your TOC text matches your heading text exactly, it reinforces a clean document structure that makes it easier for an AI system to isolate and quote the specific section relevant to a user's question, rather than summarizing the whole page vaguely.
Q: Where should the table of contents be placed on the page?
Directly after the opening paragraph(s) and before the first H2 heading, so readers see it before committing to scrolling through the full post.
Want content like this on autopilot?
Seolyn researches keywords, writes the articles, and publishes on a schedule. The first one is written the moment you create a site.