Skip to content
Haze UI

Table of contents

In-page link list with two visual levels and an active marker that follows the URL fragment.

pnpm dlx shadcn@latest add @haze/table-of-contents
Open preview in a new tab
Livesmall script

When to use

  • A long guide needs jump links to named sections and subsections
  • Readers need a shareable link to the exact section they selected

When not to use

  • The links go to separate pages. Use sidebar.
  • The trail should reflect page ancestry. Use breadcrumb.

Installation

Add the Haze registry to components.json once, then install Table of contents with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/table-of-contents
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
items*{ id: string; label: string; level?: 1 | 2 }[]–Use each heading target's ID without a hash. Level two entries are indented.
labelstring"On this page"Visible and accessible name of the navigation landmark.
currentstring–Initial section ID. A matching browser fragment takes priority.
classstring–Additional classes for placement, including sticky positioning when appropriate.

Keyboard interactions

Tab
Move between section links.
Enter
Jump to the selected heading or region.

Accessibility

  • Links navigate natively to matching IDs, including when JavaScript is disabled.
  • The matching fragment is marked with aria-current=location when scripts run.
  • Use focusable targets when keyboard users should resume navigation at a selected section.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Table of contents" with `npx shadcn@latest add @haze/table-of-contents`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import TableOfContents from "@/components/haze/ui/table-of-contents.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/table-of-contents.md

  • Customize with real content

    Adapt the Haze table-of-contents ui for our product. Replace the demo values of these props with our real content: items, label, current, class. Keep the layout, the heading level rules and these accessibility details: Links navigate natively to matching IDs, including when JavaScript is disabled. The matching fragment is marked with aria-current=location when scripts run. Use focusable targets when keyboard users should resume navigation at a selected section. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using table-of-contents, check it fits: use it when a long guide needs jump links to named sections and subsections; readers need a shareable link to the exact section they selected. Avoid it when the links go to separate pages. use sidebar.; the trail should reflect page ancestry. use breadcrumb.. Alternatives: @haze/sidebar, @haze/breadcrumb, @haze/scroll-progress.

Dependencies

  • npm: @lucide/astro
  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog