Question

Table of Contents: Implementation and SEO Benefits

6 min read

Short answer

A table of contents is a list of links at the top of a long page that jump to its sections. It helps readers who arrive for one part of a page get there without scrolling, and it gives each section a linkable address. Its search benefits are indirect and not guaranteed: Google can show links to sections of a page in results, but it decides when, and the conditions it publishes are about how the page is built, not about having a table of contents. Add one where readers need to navigate, build it with plain HTML links to heading IDs, and avoid the patterns that break deep linking.

Sources

  1. 1developers.google.com
  2. 2developers.google.com
  3. 3w3.org
  4. 4developer.mozilla.org

Ask next

When a Table of Contents Helps

The deciding question is whether readers will want to jump. Ask: would someone reasonably want section four without reading sections one to three?

Page type Table of contents
Reference or documentation page readers return to Add
Guide with distinct sections on separate subtopics Add
Page that earns impressions for queries answered in different sections Add
Continuous argument that builds from start to finish Skip
Short post with two or three sections Skip

Word count isn’t the test. A long essay meant to be read in order gains little; a shorter page covering five separate questions can gain a lot. Search Console’s Performance report shows which queries a page earns impressions for; if they map to different sections, readers are arriving with different questions.

  • “Read more” deep links. Google’s snippet documentation describes a “Read more” deep link as “a link within a snippet that leads users to a specific section on that page.” Its best practices are about the page, not the table of contents: content “immediately visible on the page to a human (and not hidden behind an expandable section or tabbed interface, for example)”, no JavaScript that controls “the user’s scroll position on page load”, and keeping the hash fragment in the URL, because removing it “breaks deep linking behavior.”
  • Sitelinks. Google’s sitelinks documentation says: “At the moment, sitelinks are automated.” Its best practices ask for headings that are “informative, relevant, and compact” and concise, relevant anchor text on internal links. A table of contents with clear section names fits those practices, but the decision stays with Google: “We only show sitelinks for results when we think they’ll be useful to the user.” See sitelinks optimization.
  • Clearer structure. Descriptive section headings help readers and describe the page’s parts; see heading hierarchy.

None of these is a ranking factor you switch on. The direct benefit is to readers.

Building It with HTML

1. Give each heading a stable ID.

<h2 id="requirements">Requirements Overview</h2>
<h2 id="soc-2">SOC 2 Requirements</h2>
<h2 id="audit-preparation">Preparing for an Audit</h2>

Use lowercase words separated by hyphens, and don’t change an ID after publishing: other pages, bookmarks and search results may link to it.

2. Put the links in a labeled navigation region. The W3C’s page regions tutorial says: “A web page can have any number of navigation menus. Use labels to identify each navigation menu.” Its example labels an in-page menu with its own heading:

<nav aria-labelledby="toc-heading">
  <h2 id="toc-heading">On this page</h2>
  <ol>
    <li><a href="#requirements">Requirements Overview</a></li>
    <li><a href="#soc-2">SOC 2 Requirements</a></li>
    <li><a href="#audit-preparation">Preparing for an Audit</a></li>
  </ol>
</nav>

3. Offset a fixed header. With a sticky header, a jump can land with the heading hidden behind it. The CSS scroll-margin-top property leaves space above the target:

h2[id] {
  scroll-margin-top: 5rem; /* set to your header's height */
}

4. Style it as navigation, with a border or background that sets it apart from body text.

Generating It Automatically

On sites with many long pages, a CMS plugin, a theme feature or a static site generator can build the list from the page’s headings. Check what the tool outputs:

  • Links in the HTML. A list built at publish time or on the server is present in the initial HTML; one built by a script in the browser depends on that script running.
  • Which levels it includes. H2 only keeps the list short; H2 and H3 suit reference pages.
  • Stable IDs. If the tool derives IDs from heading text, editing a heading changes its ID and breaks existing links to that section.

If a script adds the list, keep the heading IDs in the HTML so the section links still work when the script doesn’t run.

Design Choices

  • Place it after a short introduction, so readers know what the page is before they see the outline.
  • Keep it scannable. If the list fills a phone screen by itself, list H2s only or reorganize the page.
  • Collapsing the list is a design choice; collapsing the content isn’t. A collapsed table of contents on mobile saves space. Hiding the sections themselves behind expanders works against Google’s “Read more” guidance quoted above.
  • Touch targets need enough size and spacing to tap.
  • Current-section highlighting in a sticky sidebar helps on long reference pages. If you add it, check for a missing link before using it:
const observer = new IntersectionObserver(entries => {
  entries.forEach(entry => {
    const link = document.querySelector(`.toc a[href="#${entry.target.id}"]`);
    if (entry.isIntersecting && link) {
      document.querySelectorAll('.toc a').forEach(a => a.classList.remove('active'));
      link.classList.add('active');
    }
  });
}, { rootMargin: '-100px 0px -66%' });

document.querySelectorAll('h2[id]').forEach(h => observer.observe(h));

Without the link check, a heading that has an ID but no entry in the list throws an error.

Measuring Whether It’s Used

  • Clicks on the links, tracked as an event in your analytics:
document.querySelectorAll('.toc a').forEach(link => {
  link.addEventListener('click', () => {
    gtag('event', 'toc_click', { section: link.getAttribute('href') });
  });
});
  • Engagement on the page in GA4, compared before and after over comparable periods.
  • Search Console clicks and impressions for the page, over the same comparable periods.

If almost no one clicks the links, the list may be hard to find, or the page may not need one.

Table of Contents Pitfalls

  • Adding one to every page, including short posts.
  • Link text that doesn’t match the heading it points to.
  • Broken jumps after a heading’s text or ID changes; test every link after edits.
  • A list that only exists after JavaScript runs, with no IDs in the HTML.
  • Hiding sections behind tabs or expanders, which Google’s deep-link guidance warns against.
  • Scripts that reset the scroll position or strip the # fragment on load.
  • A stale list after sections are added, removed or reordered.

Before editing a heading on a published page, check whether its ID is generated from the heading text: if it is, set the old ID on the heading by hand, so that links, bookmarks and search results pointing to that section keep landing on it.

Link profile