---
title: "Preview Rail"
description: "A column of ticks for the sections of a page. The ticks near the pointer grow, and a card glides to the item and names it."
url: https://gelatinui.com/components/preview-rail
markdown_url: https://gelatinui.com/components/preview-rail.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/preview-rail"
version: "2026-11-09"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Preview Rail

> A column of ticks for the sections of a page. The ticks near the pointer grow, and a card glides to the item and names it.

Page: https://gelatinui.com/components/preview-rail

## When to use it

Best for: A thin rail of ticks for the sections of a long page, with a card that names each one.

- Give the root an `aria-label`, and a `label` to each item: a tick has no text.
- Set `value` from the scroll to follow the page.
- Use `orientation="horizontal"` for a row of slides or steps.

## When not to use it

- For a list of headings people read, use a [Track Contents](https://gelatinui.com/components/track-contents.md).
- For a few views with text labels, use [Tabs](https://gelatinui.com/components/tabs.md).

## Notes for agents

- It is a Base UI Toolbar: one Tab stop, arrow keys, Home, and End.
- A touch press that moves along the rail scrubs, and the release opens the item.
- The card is as tall as the tallest preview, so it never changes size.
- Put `PreviewRailTitle` and `PreviewRailDescription` in an item for its card.

## Anatomy

```text
PreviewRail
├─ PreviewRailItem (0..n)
├─ PreviewRailLink (0..n)
├─ PreviewRailTitle (0..n)
├─ PreviewRailDescription (0..n)
└─ PreviewRailSeparator (0..n)
```

## API reference

### PreviewRail

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `value` | `string \| null` |  | The value of the active item (controlled). `null`: no item is active. |
| `defaultValue` | `string \| null` | null | The active item at the start (uncontrolled). |
| `onValueChange` | `function` |  | Called with the item value on a click, a key press, or the end of a scrub, and the Base UI change details of that click. |
| `orientation` | `PreviewRailOrientation` | "vertical" | The axis of the rail (default `vertical`). |
| `side` | `"end" \| "start"` | "end" | Where the card shows (default `end`): `end` is the inline end of a vertical rail (the right in left to right) or under a horizontal one; `start` is the other side. |
| `size` | `PreviewRailSize` | "default" | The pitch and tick size: `sm` 12px, `default` 16px, `lg` 20px per item. |
| `magnification` | `number` | 2 | The largest tick scale under the pointer (default 2). `1` turns the growth off. |
| `distance` | `number` | 3 | How far the growth reaches, in ticks (default 3). |
| `cardClassName` | `string` |  | Classes of the card (its width, for example). |

Also takes every prop of Base UI `Toolbar.Root`: https://base-ui.com/react/components/toolbar

### PreviewRailItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | The card content (`PreviewRailTitle`, `PreviewRailDescription`, or your own). |
| `className` | `string` |  |  |
| `value` | `string` |  | The item value: unique in the rail. |
| `label` | `string` |  | The name of the item for screen readers, and the card title when there are no children. |

Also takes every prop of Base UI `Toolbar.Button`: https://base-ui.com/react/components/toolbar

### PreviewRailLink

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | The card content (`PreviewRailTitle`, `PreviewRailDescription`, or your own). |
| `className` | `string` |  |  |
| `value` | `string` |  | The item value: unique in the rail. |
| `label` | `string` |  | The name of the item for screen readers, and the card title when there are no children. |

### PreviewRailTitle

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

### PreviewRailDescription

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

### PreviewRailSeparator

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

Also takes every prop of Base UI `Toolbar.Separator`: https://base-ui.com/react/components/toolbar

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| PreviewRail | `preview-rail` | `data-disabled` |  |  |
| PreviewRailItem | `preview-rail-item` | `data-disabled` |  |  |
| PreviewRailLink | `preview-rail-item` | `data-disabled` |  |  |
| PreviewRailTitle | `preview-rail-title` |  |  |  |
| PreviewRailDescription | `preview-rail-description` |  |  |  |
| PreviewRailSeparator | `preview-rail-separator` |  |  |  |

## Usage

Put one item for each slide or section in the rail. The title and the description in an item fill its preview card.

```tsx title="slide-rail.tsx"
"use client";

import { useState } from "react";

import {
  PreviewRail,
  PreviewRailDescription,
  PreviewRailItem,
  PreviewRailTitle,
} from "@/components/pro/navigation/preview-rail";

const SLIDES = [
  { id: "intro", label: "Q3 review", description: "Slide 1 · Agenda and goals" },
  { id: "revenue", label: "Revenue by region", description: "Slide 2 · Europe leads at $4.2M" },
  { id: "churn", label: "Churn", description: "Slide 3 · Down to 2.1% a month" },
  { id: "plan", label: "Q4 plan", description: "Slide 4 · Three bets for the next quarter" },
];

export function SlideRail() {
  const [slide, setSlide] = useState<string | null>("revenue");
  return (
    <PreviewRail aria-label="Slides" value={slide} onValueChange={setSlide}>
      {SLIDES.map((item) => {
        return (
          <PreviewRailItem key={item.id} value={item.id} label={item.label}>
            <PreviewRailTitle>{item.label}</PreviewRailTitle>
            <PreviewRailDescription>{item.description}</PreviewRailDescription>
          </PreviewRailItem>
        );
      })}
    </PreviewRail>
  );
}
```

## 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-pro/preview-rail
```

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

## Built on

- [Direction](https://gelatinui.com/components/direction.md)

## 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

- [Track Contents](https://gelatinui.com/components/track-contents.md)
- [Table of Contents](https://gelatinui.com/components/table-of-contents.md)
- [Toolbar](https://gelatinui.com/components/toolbar.md)
- [Scroll Area](https://gelatinui.com/components/scroll-area.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Tab | Moves the focus to the current item. The card shows for it. |
| Arrow keys | Move the focus along the rail. |
| Home / End | Move the focus to the first or the last item. |
| Enter / Space | Opens the focused item. |

## Motion

| Part | Motion |
| --- | --- |
| Ticks | indicator · the ticks near the pointer grow, and the marker moves to the current item |
| Card | glide · the card moves to the item under the pointer, and its content rolls |
| Card show | popup · the card fades in, and fades out on leave |
