---
title: "Table of Contents"
description: "The headings of a long page as links, with the section you read marked on a rail as you scroll."
url: https://gelatinui.com/components/table-of-contents
markdown_url: https://gelatinui.com/components/table-of-contents.md
access: free
install: "npx shadcn@latest add @gelatin-ui/table-of-contents"
registry_item: https://gelatinui.com/r/table-of-contents.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Table of Contents

> The headings of a long page as links, with the section you read marked on a rail as you scroll.

Page: https://gelatinui.com/components/table-of-contents

## When to use it

Best for: The headings of a long page as links, with the section you read marked on a rail.

- Use `root` for a box that scrolls.
- Use `offset` under a sticky header.
- Use one nested list per heading level.

## When not to use it

- For the steps of a task, use a [Stepper](https://gelatinui.com/components/stepper.md).

## Notes for agents

- Each `TableOfContentsLink` adds its heading id, so the ids come from the links.
- `value` and `onValueChange` hold the heading id.
- A router link comes in through `render`.
- With no links, the nav is hidden.

## Anatomy

```text
TableOfContents
├─ TableOfContentsTitle (0..n)
├─ TableOfContentsList (0..n)
├─ TableOfContentsItem (0..n)
├─ TableOfContentsLink (0..n)
└─ TableOfContentsIndicator (0..n)
```

## API reference

### TableOfContents

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `aria-label` | `string` |  | Defines a string value that labels the current element. The name of the landmark for screen readers. Default "On this page". Translate it. |
| `value` | `string \| null` |  | The id of the current heading (controlled). Use with `onValueChange`. |
| `defaultValue` | `string \| null` | null | The id that is current on the first paint, until the box scrolls or a click (uncontrolled). |
| `onValueChange` | `function` |  | Called with the new heading id on scroll and on a link click. |
| `offset` | `number` | 0 | The height in px of a sticky header over the scroll box (default `0`). Give the headings the same `scroll-margin-top`, so a jump to a hash lands under the header. |
| `root` | `Element \| null` | null | The scroll box that holds the headings, if it is not the page (an element, not a ref). |
| `trackInView` | `boolean` | false | Marks the links of the sections on screen with `data-in-view` (default `false`). |

### TableOfContentsTitle

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### TableOfContentsList

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### TableOfContentsItem

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### TableOfContentsLink

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` |  | The id of the heading. Default: the `href` without `#`. Set it when `render` mounts a router link that builds its own `href` (`render={<Link to="/docs" hash="install" />}`). |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

### TableOfContentsIndicator

No props of its own: `className`, `children`, and every other prop go to the element it renders.

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| TableOfContents | `table-of-contents` |  |  |  |
| TableOfContentsTitle | `table-of-contents-title` |  |  |  |
| TableOfContentsList | `table-of-contents-list` |  |  |  |
| TableOfContentsItem | `table-of-contents-item` |  |  |  |
| TableOfContentsLink | `table-of-contents-link` | `data-active` |  |  |
| TableOfContentsIndicator | `table-of-contents-indicator` | `data-hidden`, `data-ready` | `--table-of-contents-indicator-height`, `--table-of-contents-indicator-top` | `motion-timing` |

## Usage

Put a list of links and the indicator in the root.

```tsx title="page-links.tsx"
import {
  TableOfContents,
  TableOfContentsIndicator,
  TableOfContentsItem,
  TableOfContentsLink,
  TableOfContentsList,
  TableOfContentsTitle,
} from "@/components/ui/table-of-contents";

export function PageLinks() {
  return (
    <TableOfContents>
      <TableOfContentsTitle>On this page</TableOfContentsTitle>
      <TableOfContentsList>
        <TableOfContentsItem>
          <TableOfContentsLink href="#install">Install</TableOfContentsLink>
        </TableOfContentsItem>
        <TableOfContentsIndicator />
      </TableOfContentsList>
    </TableOfContents>
  );
}
```

## Compose

Rules:

- Touch targets (`touch-targets`): Give every control a hit area of at least 44 px on touch screens, even when it looks smaller.
- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/table-of-contents
```

It adds 13 registry items: 12 files, 2537 lines, and the npm packages `@base-ui/react`, `@mantine/hooks`, `@xstate/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Breadcrumb](https://gelatinui.com/components/breadcrumb.md)
- [Navigation Menu](https://gelatinui.com/components/navigation-menu.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | Moves through the links. |
| Enter | Goes to the heading. |

## Accessibility

It is a `nav` landmark with nested lists.

The current link has `aria-current`.
