# Table of Contents

> An "On this page" list for docs and long reads: an indicator glides to the section you're reading and the rail fills as you go.

Category: Navigation · MotionKit Plus · Updated 2026-11-10 · Live demo: https://www.motionkitui.com/components/table-of-contents

## When to use it

Documentation, guides, changelogs, legal pages and long blog posts, usually in a sticky sidebar beside the content.

## How it works

On scroll, once per frame, it finds the last heading whose top has passed a reading line a set distance down the screen; at the very bottom of the page, the final section wins. The active link's position is measured and a spring moves a bright indicator onto it, while a fainter line fills the rail down to it. Clicking a link scrolls to the heading, moves keyboard focus there and updates the address without adding to the history.

## Installation

Part of MotionKit Plus (https://www.motionkitui.com/pricing). Subscribers install it with `npx shadcn@latest add @motionkit/table-of-contents` after adding their registry token from https://www.motionkitui.com/account.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `TocItem[]` |  | The headings to list: their id, title and level (2, or 3 to indent). |
| `title` | `string` | `"On this page"` | The list's heading and landmark name. |
| `offset` | `number` | `96` | How far down the screen a heading counts as reached, in px. Allow for a sticky header. |
| `root` | `HTMLElement \| null` |  | A scrolling element to follow instead of the page. |
| `accent` | `string` | `"#5FAEB4"` | Colour of the indicator and the rail. |

## Accessibility

- **Keyboard: Pass.** Ordinary links in order; following one scrolls to its heading and moves focus there, so the next Tab continues from that section.
- **Screen readers: Pass.** A navigation landmark with its title; the section being read is marked with aria-current.
- **Reduced motion: Pass.** With reduced motion on, links jump rather than scroll smoothly and the indicator moves without gliding.
- **Colour contrast: Pass.** Links measure 7.7:1 on the site's dark and the current one 17:1, in bold too, so the active section doesn't rely on colour alone.
