Toc

Table of contents with scroll-spy highlighting of the active section

Category: navigation · WCAG 2.2-AA · toc, table-of-contents, navigation, scroll-spy, anchor

Props

PropTypeDefaultDescription
items{ id: string; label: string; level?: number }[]The items to render.
activeIdstringControlled active item id; disables built-in scroll-spy when set
onActiveChange(id: string) => voidCalled with the id of the active section when it changes.
labels{ nav?: string }Overrides for the component’s user-visible strings (i18n).
classNamestringAdditional CSS class names merged onto the root element.

Design tokens

When to use

When not to use

How to build an accessible Toc in React →

Examples

Basic

<Toc items={[{ id: 'intro', label: 'Introduction' }, { id: 'usage', label: 'Usage' }, { id: 'api', label: 'API', level: 3 }]} />

Controlled active item

Pass activeId to drive the highlight yourself; scroll-spy is disabled.

<Toc activeId="usage" items={[{ id: 'intro', label: 'Introduction' }, { id: 'usage', label: 'Usage' }]} />

Related components

← Back to docs