Outline

Links to the sections of a page, marking the one in view.

Overview

This guide takes a new project from an empty folder to a deployed site. Each step builds on the one before it, so work through them in order the first time.

Most steps take a few minutes. Deploying takes longer the first time, while the build cache warms up.

Installing

Install the command-line tool with your package manager, then sign in. The tool remembers your account, so you only sign in once on each computer.

Run the init command in an empty folder. It asks for a project name and writes a config file with sensible defaults.

Configuring

The config file sets where the site builds from and which commands run. Leave the defaults alone until something needs to change.

Environment variables

Keep secrets out of the config file. Add them in the dashboard instead, where each one can differ between preview and production.

A build reads variables when it starts, so redeploy after changing one.

Deploying

Push to the main branch to deploy to production. Every other branch gets a preview address of its own, which updates on each push.

If a deploy fails, its log shows the step that failed and the output just before it.

Installation

  1. Add the registryOnce per project
  2. Add outline

Usage

Link each OutlineItem to a heading's id. As the page scrolls, the outline marks the last heading that has reached the top, or the last one once the page can't scroll further, and the line beside it slides to follow. It follows whichever element the headings scroll in, the window or a panel, and checks again when its links change.

Clicking a link scrolls its heading smoothly into place and moves focus to it, so Tab carries on from that section. Scrolling the headings yourself during the animation takes over from it, and so does the scroll stopping anywhere else. When the headings scroll with the window, the heading's id goes in the address once it arrives. A heading lands below the scroller's scroll-padding-top and its own scroll-margin-top, and it counts as reached at the same point, so make room there for any header fixed over the content.

A link's value is the part of its href after #, unless you pass one. Only links to the current page scroll this way: other links, and links whose onClick calls preventDefault, such as a router's link passed to render, navigate as they would anyway, and the outline only marks them.

label names the outline and shows above the links. Without it, give Outline an aria-label. This site's own On this page column is an Outline.

Composition

Examples

Levels

level indents a link under the one before it, from 1 to 4.

Controlled

Pass value and onValueChange to choose the marked section yourself. The outline still calls onValueChange as the page scrolls and when a link is clicked.

Props

The tables leave out className, style and render. Parts built on Base UI take them as its styling and composition guides describe.

Outline

OutlineItem