Toc
Table of contents navigation
Table of contents with scroll spy, progress indicator, and multiple variants.
Usage
Scroll spy
The toc automatically detects h2 and h3 headings within an <article> element. As you scroll, the current heading is highlighted.
When multi mode is enabled, all visible headings are highlighted as a range.
Variants
Default
Full toc with border-based highlighting showing which section is active.
With multi-heading range:
With zigzag lines connecting nested headings:
Minimal
Simpler toc with scroll progress indicator on a vertical track.
With zigzag progress:
Inline
Collapsible toc that goes inside the content area.
With custom title:
Always open:
Open by default:
UseToc hook
Access toc state directly for custom implementations.
Return value
| field | type | description |
|---|---|---|
| headings | Heading[] | H2 and h3 elements with id, text, level |
| active | string | ID of the first active heading |
| activeRange | string[] | IDs of all visible headings (multi mode) |
Heading type
Props
| prop | type | default | description |
|---|---|---|---|
| variant | "default" | "minimal" | "inline" | "default" | Toc style |
| zigzag | boolean | false | Show zigzag lines connecting headings |
| multi | boolean | false | Highlight multiple active headings |
| title | string | "on this page" | Header text (inline only) |
| collapsible | boolean | true | Can collapse (inline only) |
| defaultOpen | boolean | false | Start expanded (inline only) |