Skip to content
IndexRequest a UIAboutContact

Scrollspy Table of Contents

A table of contents that highlights the section you are reading and scrolls to a section when clicked.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Clean documentation page layout with a narrow sticky table of contents on the left titled On this page, four short entries where the second is highlighted in bold dark text with a thin vertical bar on the left, and a long article on the right with section headings Overview, Setup, Usage and FAQ, light theme, flat modern style, plenty of white space. Variants: the first and last entries active. Negative: nested deep lists, gradients, heavy borders, text errors, clutter. Reduced motion: static layout.

About this pattern

Definition

Scrollspy keeps a table of contents in sync with the reader. As the page scrolls, the entry for the section nearest the top is highlighted, so people always know where they are in a long document and can jump elsewhere with one click.

Purpose & UX principles

  • Highlight the last section whose top has passed a line a little below the top of the view.
  • Clicking an entry scrolls smoothly and moves focus to the section heading.
  • Keep the list sticky so it stays visible; mark the active link with aria-current.

Interaction states

  • A scrollable document with four sections and a contents list that follows it.

Motion specification

  • The marker slides between entries over 200ms; clicking scrolls smoothly.
  • Reduced motion: no slide and the jump is instant.

Responsive behaviour

  • On narrow screens collapse the list into a menu or a horizontal strip.
  • Do not highlight two entries at once.

Code

HTML
<div class="bx"><div class="dc"><nav class="tc" aria-label="On this page"><b>On this page</b><ul id="tc"></ul></nav><div class="ar" id="ar"></div></div></div>

Related patterns

Reading Progress Bar

↗
Reading Progress BarLayout & Scrolling

Breadcrumb

↗
BreadcrumbNavigation

Tab Navigation

↗
Tab NavigationNavigation