Impeccable

Section Rail

A scrolling page where each section's name rises letter by letter from a small list and grows into a big title as the section reaches the top.

ScrollNavigationNo extra packagesLight + darkMobile

Impeccable UI

The library

Let's make something for Humans once again.

Impeccable UI is a library of React components that move. Every piece starts with its motion: how it arrives, how it answers your hand, and how it gets out of the way.

Each item is one file you own. Copy it into your project, read it top to bottom, and change what you like. No packages to keep in step, no theme to fight.

It is free and open source, written in TypeScript with a plain JavaScript copy, and loved by 100k+ humans who care how their product feels.

Components

Pieces that feel alive

Galleries, lists and counters with a pulse.

Components are the everyday parts of a page: a gallery, a list you can peek into, a number that settles when it changes. Each one is built so the motion explains what just happened.

They follow your theme in light and dark, and on phones they swap hover for a simple tap or drag, so nothing feels broken on a small screen.

Buttons

Press to feel

Buttons people want to press.

A button is the moment someone decides. The buttons here give that moment weight: a press you can feel, a calm wait while it loads, and a small lift when it works.

Every effect comes in slowly and leaves quickly, so it feels considered without ever slowing anyone down.

They sit next to your own buttons without a fight, and keep their full meaning for keyboards and screen readers.

Loaders

While you wait

Waiting, made watchable.

Nobody likes to wait, but a good loader makes the wait feel shorter. These loaders are calm enough to look at for more than a second, and clear about the fact that something is happening.

With reduced motion turned on they settle into a quiet version that still says the same thing.

Get started

One command

Make it yours today.

Install any item with one command, or copy its file by hand. Each page also gives you two prompts: Install adds the item exactly as it is, and Blend fits it to your brand after a few short questions.

Pick one piece, drop it into a page you already have, and watch how it changes the feel of everything around it.

npx shadcn@latest add https://impeccable-ui.com/r/section-rail.json
Scroll inside the box. When a section reaches the top, its name rises from the gray list and grows, letter by letter, into the big title, while the one before it eases down to small and gray. Click any gray name to glide there, and scroll back up to see it play in reverse.

Run it in a project set up with shadcn. No other packages needed. Or open and copy the file into components/ui/section-rail.tsx.

Prompts

Paste one into Claude Code, Cursor or any AI coding tool. Install adds this exact rail and asks only which page it goes on. Blend asks four short questions (the page, the section names, the type and how many earlier titles stay), then fits it to your product without changing how it moves.

# Section Rail

A 1-file React component from Impeccable. Add it to this project so it works and looks exactly like the source below, on the one page I choose, and change nothing else.

A long scrolling page that always shows where you are. Every section's name waits in a small gray list at the bottom right. When a section reaches the top, its name rises from the list and grows, letter by letter, into a big title at the top right, while the title before it eases down to the small gray size and sits above it. Scrolling back up plays it in reverse, quicker. A click on any gray name glides the page to that section. A thin ruler at the right edge has fine ticks, a numbered mark where each section starts, and a line that runs down with you reading 02/05. Black and white only, in the text color.

## Before you build: one question

Look through this project first: its long pages (landing page, about, a story or case study, docs), how each is split into sections, and the heading each section already has. Then ask me this in one message and wait for my answer:

- **Which page should it wrap?** Suggest the 1–3 long pages in my code it fits best, the sections it would show on each, and the short name (one or two words) you'd give each section from its heading. I can pick one or name another.
  *Why: the rail only helps on a page long enough to get lost in, and the names are what people will read.*

Ask nothing else. If I say *skip*, use the best suggestion.

## Keep it as it is

The two places, the name growing letter by letter into the big title, the title before it easing down to small and gray, the quicker reverse, the ruler with its section marks and reading, black and white only, and their timing and easing, are the design. Keep them exactly as in the source. If something doesn't fit my project, tell me instead of changing it.

- Add only the component file and wrap the sections of the one page I picked: move each section's existing content into `content` without changing it. Don't add packages, change other files, or restyle anything.
- Don't add the demo parts from the Impeccable website: the five demo sections about Impeccable UI (their paragraphs and the Browse components button), the card around the preview and the home page's TV.

## Fastest path

If this project has a `components.json` (shadcn), run `npx shadcn@latest add https://impeccable-ui.com/r/section-rail.json`.
If the command succeeds, only fix import paths to match this project and skip ahead. If it fails or there is no `components.json`, build it by hand as below.

## Build it

- Stack: React 18 or 19 with TypeScript. No other packages: script only decides where each name belongs, and every move is a CSS transition on transform and opacity, so the browser runs it smoothly. Its styles sit in a `<style>` tag inside the file.
- JavaScript project? Name the file `section-rail.jsx` and remove the type annotations; nothing else changes.
- Create this file, in this project's usual place for components:
  - `components/ui/section-rail.tsx`
- Keep these exports and their names: `SectionRail`, `SectionRailProps` and `SectionRailSection`.
- Keep `"use client"` at the top in Next.js App Router projects. In other setups it is harmless.
- Keep the tuning values at the top exactly as written: `GROW_MS`, `GROW_EASE`, `STAGGER_MS`, `SETTLE_MS`, `BACK_MS`, `BACK_EASE`, `BACK_STAGGER_MS`, `GLIDE_MIN`, `GLIDE_MAX`, `GLIDE_PER_PX`, `TOP_AT`, `GIVE`, `TONE`, `LIT_IN_MS`, `LIT_OUT_MS`, `FADE_MS`, `TICK` and the `CSS` block. They are the design and its timing.
- Keep the fallbacks: with `prefers-reduced-motion: reduce` nothing moves: each name fades out and back in at its new place. Every section gets its title as a hidden heading for screen readers; the moving letters are hidden from them. Pointing at a name only lights it on devices with a mouse.

## Use it

```tsx
"use client";
import { SectionRail } from "@/components/ui/section-rail";

export function Story() {
  return (
    <SectionRail
      sections={[
        { title: "Intro", content: <Intro /> },
        { title: "Features", content: <Features /> },
        { title: "Pricing", content: <Pricing />, id: "pricing" },
      ]}
    />
  );
}
```

- `sections` are the page's parts, top to bottom: a short `title` (shown in capitals) and the `content`. Add `id` to keep an existing #link working.
- Leave out `height` on a page, so it follows the page scroll. Give it a `height` (like `560` or `"70vh"`) only to make it its own scroll box.
- `keep` is how many earlier titles stay above the current one (2). `ruler={false}` hides the ruler.
- It takes its colors from `--foreground` and `--background` (or `--fg` and `--bg`), so it follows light and dark mode. Leave the right edge free: the ruler takes about 40px on a phone and 52px on wider screens.
- The last section is given at least one screen of height, so its name can reach the top.

## How the rail works

Read this before you touch anything, so you know what the code does and why it must stay as it is.

1. **Two places.** Every name is either in the small gray list at the bottom right (its section has not reached the top yet) or at the top right (it has). Both sit on solid bands in the background color with a hairline edge (no shadow), so the page's own text never runs under them; the bottom band eases down as names leave it. The newest section at the top is the big, full-strength title; the `keep` titles before it sit above, small and gray; older ones fade away.
2. **When it moves.** A name goes to the top when its section's top reaches the top of the view, with 10px of give so it never flickers between the two.
3. **The growth.** The name rises from the list and grows to the big title in 1.4 seconds: it starts softly, never jumps, and settles with a long, gentle landing. Its letters start 32ms apart, left to right, so the word grows like a soft wave.
4. **The title before it.** At the same time, it eases down to the small gray size in 1.1 seconds, all letters together.
5. **Going back.** Scrolling up reverses every move, a little quicker (0.6 seconds, 14ms apart). A move that is interrupted turns back from wherever it is, with no jump.
6. **The ruler.** A tick every 16px, a longer one every fifth, a numbered mark where each section starts, and a line that runs down with the scroll and reads which section you are in, like 02/05.
7. **Clicks.** Every name in the bottom list and the top list can be clicked to glide the page to its section, in 0.9 to 1.7 seconds depending on the distance, eased at both ends. A wheel, touch or key from the visitor stops the glide at once. A name you point at with a mouse turns full strength.

## Check

- It type-checks and the page renders with no console errors.
- Scrolling down, each name rises from the bottom list and grows letter by letter into the big title when its section reaches the top, with the earlier titles small and gray above it. Scrolling up plays it back, quicker.
- Clicking a gray name glides the page to that section.
- It looks right in light and dark mode (check both), black and white only.
- It fits on a phone without scrolling sideways, the titles fit, and the motion stays smooth.
- With `prefers-reduced-motion: reduce`, names only fade from place to place.
- Nothing else on the site looks or behaves differently.
- Finish with a short report: the files you added or changed, the page and the section names, and every place where you had to do something differently from the source, and why.

## Source

The reference implementation. Copy it as-is, then apply only the changes listed above.

### `components/ui/section-rail.tsx`

```tsx
"use client";

/**
 * Section Rail, from Impeccable.
 *
 * A long scrolling page that always tells you where you are. Every section's
 * name waits in a small gray list at the bottom right. When a section reaches
 * the top, its name rises from the list and grows, letter by letter, into a
 * big title at the top right: the section you are in now. The title before it
 * eases down to the small gray size and sits above it. Scroll back up and it
 * all plays in reverse, quicker.
 *
 * Both places sit on calm, solid bands in the background color, so your own
 * text never runs under the names.
 *
 * Every name you can see is also a link: click a gray name at the bottom or an
 * earlier title at the top and the page glides to that section.
 *
 * A thin rail on the right carries a ruler: fine tick marks, a numbered mark
 * where each section starts, and a line that runs down with you and reads which
 * section you are in, like 02/05. Black and white only, in your text color.
 *
 * Give it a height to make it its own scroll box, or leave the height out and
 * it follows the page scroll.
 *
 * No packages. Script only decides where each name belongs; every move is a
 * CSS transition on transform and opacity, so the browser runs it smoothly off
 * the main thread.
 */

import { useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react";

export type SectionRailSection = {
  /** The section's name. It is shown in capitals, so write it as normal: "Get started". */
  title: string;
  /** What the section holds. */
  content: ReactNode;
  /** Optional id, so a link like #pricing can jump to it. */
  id?: string;
};

export type SectionRailProps = {
  /** The sections, top to bottom. */
  sections: SectionRailSection[];
  /** Makes it its own scroll box this tall: 560 (px) or any CSS length like "70vh". Leave out to follow the page scroll. */
  height?: number | string;
  /** How many earlier titles stay above the current one. Older ones fade away. Default: 2. */
  keep?: number;
  /** The ruler on the rail: tick marks, section marks and the scroll line. Default: true. */
  ruler?: boolean;
  /** Name of the scroll box for screen readers (only with a height). Default: "Sections". */
  "aria-label"?: string;
  className?: string;
  style?: CSSProperties;
};

/* ---------- the design: keep as written ---------- */

const GROW_MS = 1400; // a name rising from the list and growing into the big title: slow and calm
const GROW_EASE = "cubic-bezier(.45,0,.15,1)"; // starts softly, never jumps, then a long gentle landing
const STAGGER_MS = 32; // between letters, left to right, so the word grows like a soft wave
const SETTLE_MS = 1100; // the title before it easing down to the small gray size, and the list above moving up
const BACK_MS = 600; // every move going back when you scroll up: quicker than coming in, still smooth
const BACK_EASE = "cubic-bezier(.4,0,.2,1)"; // smooth both ends, no snap
const BACK_STAGGER_MS = 14; // between letters going back
const GLIDE_MIN = 900; // ms: a click on a name glides the page there, never faster than this
const GLIDE_MAX = 1700; // ms: and never slower than this, however far it goes
const GLIDE_PER_PX = 0.55; // ms per px of distance, between those two
const TOP_AT = 6; // px: a section counts as current when its top is this close to the top
const GIVE = 10; // px of give, so a name never flickers between two places
const TONE = 0.55; // how strong the small gray names are (share of the text color)
const LIT_IN_MS = 260; // a gray name you point at turns full strength
const LIT_OUT_MS = 160; // and lets go quicker
const FADE_MS = 220; // reduced motion: names fade out, move, and fade back in
const TICK = 16; // px between ruler ticks; every fifth one is longer

const CSS = `
.srl{--srl-fg:var(--foreground,var(--fg,CanvasText));--srl-bg:var(--background,var(--bg,Canvas));position:relative;container:srl/inline-size;background:var(--srl-bg);color:var(--srl-fg)}
.srl[data-own]{height:var(--srl-h);overflow-y:auto;overscroll-behavior:contain;scrollbar-width:none}
.srl[data-own]::-webkit-scrollbar{display:none}
.srl[data-own]:focus-visible{outline:2px solid color-mix(in srgb,var(--srl-fg) 45%,transparent);outline-offset:-2px}
.srl-o{--srl-s:11px;--srl-b:24px;--srl-g:40px;--srl-p:14px;position:sticky;top:0;z-index:2;height:var(--srl-v,var(--srl-h));margin-bottom:calc(-1 * var(--srl-v,var(--srl-h)));overflow:hidden;pointer-events:none;user-select:none;-webkit-user-select:none;opacity:0;transition:opacity .5s ${GROW_EASE}}
.srl-o[data-ready]{opacity:1}
.srl-c{--srl-g:40px;position:relative;padding-right:var(--srl-g)}
@container srl (min-width:560px){.srl-o,.srl-c{--srl-s:13px;--srl-b:38px;--srl-g:52px;--srl-p:20px}}
@container srl (min-width:960px){.srl-o,.srl-c{--srl-s:14px;--srl-b:48px;--srl-g:56px;--srl-p:28px}}
.srl-f,.srl-m{position:absolute;left:0;top:0;font-size:var(--srl-b);line-height:1;font-weight:600;letter-spacing:.02em;text-transform:uppercase;white-space:pre}
.srl-f{transform-origin:50% 50%;will-change:transform,opacity;opacity:0;color:var(--srl-fg)}
.srl-m{visibility:hidden;display:flex}
.srl-hit{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;cursor:pointer;pointer-events:auto;visibility:hidden;-webkit-tap-highlight-color:transparent}
.srl-hit[data-on]{visibility:visible}
.srl-band{position:absolute;left:0;right:var(--srl-g);background:var(--srl-bg)}
.srl-band[data-at=top]{top:0;border-bottom:1px solid color-mix(in srgb,var(--srl-fg) 8%,transparent)}
.srl-band[data-at=bottom]{bottom:0;border-top:1px solid color-mix(in srgb,var(--srl-fg) 8%,transparent);will-change:transform}
.srl-mark{position:absolute;right:0;top:0;width:var(--srl-g);height:1px;background:var(--srl-fg);will-change:transform}
.srl-mark span{position:absolute;right:4px;top:5px;font:600 9px/1 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.04em;color:var(--srl-fg);font-variant-numeric:tabular-nums}
.srl-s{position:relative}
.srl-s:last-child{min-height:var(--srl-v,var(--srl-h))}
.srl-r{position:absolute;top:0;bottom:0;right:0;width:var(--srl-g);border-left:1px solid color-mix(in srgb,var(--srl-fg) 10%,transparent);pointer-events:none;user-select:none;-webkit-user-select:none;
background:repeating-linear-gradient(to bottom,color-mix(in srgb,var(--srl-fg) 18%,transparent) 0 1px,transparent 1px ${TICK}px) right top/6px 100% no-repeat,
repeating-linear-gradient(to bottom,color-mix(in srgb,var(--srl-fg) 32%,transparent) 0 1px,transparent 1px ${TICK * 5}px) right top/11px 100% no-repeat}
.srl-r i{position:absolute;right:0;width:calc(var(--srl-g) * .5);height:1px;background:color-mix(in srgb,var(--srl-fg) 55%,transparent)}
.srl-r b{position:absolute;right:calc(var(--srl-g) * .5 + 4px);font:600 9px/1 ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--srl-fg);transform:translateY(-50%);transition:opacity .2s}
.srl-r b[data-hide]{opacity:0}
.srl-sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
`;

type Letter = {
  s: number; // section
  i: number; // place in the word
  el: HTMLSpanElement;
  w: number; // width at the big size
  off: number; // left edge in the word at the big size
};

type Spot = { key: string; rank: number; k: number; y: number; a: number }; // where a whole name sits

const cssLength = (h: number | string) => (typeof h === "number" ? `${h}px` : h);
const two = (n: number) => String(n).padStart(2, "0");

export function SectionRail({
  sections,
  height,
  keep = 2,
  ruler = true,
  "aria-label": ariaLabel = "Sections",
  className,
  style,
}: SectionRailProps) {
  const own = height !== undefined;
  const rootRef = useRef<HTMLDivElement>(null);
  const overlayRef = useRef<HTMLDivElement>(null);
  const contentRef = useRef<HTMLDivElement>(null);
  const markRef = useRef<HTMLDivElement>(null);
  const labelRef = useRef<HTMLSpanElement>(null);
  const topBand = useRef<HTMLDivElement>(null);
  const bottomBand = useRef<HTMLDivElement>(null);
  const [starts, setStarts] = useState<number[]>([]);

  const words = useMemo(() => sections.map((s) => Array.from(s.title)), [sections]);
  const sig = words.map((w) => w.join("")).join("\u0000");

  useEffect(() => {
    const root = rootRef.current;
    const overlay = overlayRef.current;
    const content = contentRef.current;
    if (!root || !overlay || !content) return;

    const reduce = matchMedia("(prefers-reduced-motion: reduce)");
    const canHover = matchMedia("(hover: hover) and (pointer: fine)");
    const secs = Array.from(content.querySelectorAll<HTMLElement>(":scope > .srl-s"));
    const hits = Array.from(overlay.querySelectorAll<HTMLButtonElement>(".srl-hit"));
    const nums = () => content.querySelectorAll<HTMLElement>(".srl-r b");
    const N = secs.length;
    const atTop = new Array<boolean>(N).fill(false);
    const tops = new Array<number>(N).fill(0);
    const placed: (Spot | null)[] = new Array(N).fill(null); // where each name was last sent
    const timers: number[] = [];

    const bySection: Letter[][] = secs.map(() => []);
    overlay.querySelectorAll<HTMLSpanElement>(".srl-f").forEach((el) => {
      const s = Number(el.dataset.s);
      bySection[s]?.push({ s, i: Number(el.dataset.i), el, w: 0, off: 0 });
    });

    // Sizes come from CSS (they change with the width), read once per layout.
    let B = 24; // big size
    let S = 11; // small size
    let G = 40; // rail width
    let P = 14; // gap to the edges
    let W = 0;
    let H = 0;
    let wordW: number[] = [];

    function measure() {
      const cs = getComputedStyle(overlay!);
      B = parseFloat(cs.getPropertyValue("--srl-b")) || B;
      S = parseFloat(cs.getPropertyValue("--srl-s")) || S;
      G = parseFloat(cs.getPropertyValue("--srl-g")) || G;
      P = parseFloat(cs.getPropertyValue("--srl-p")) || P;
      // An own scroll box can be sized in % or any unit: the view is its measured height.
      if (own) root!.style.setProperty("--srl-v", `${root!.clientHeight}px`);
      W = overlay!.clientWidth;
      H = overlay!.clientHeight;
      wordW = [];
      overlay!.querySelectorAll<HTMLElement>(".srl-m").forEach((row, s) => {
        const left = row.getBoundingClientRect().left;
        let right = left;
        Array.from(row.children).forEach((span, i) => {
          const r = span.getBoundingClientRect();
          const L = bySection[s]?.[i];
          if (L) {
            L.w = r.width;
            L.off = r.left - left;
          }
          right = r.right;
        });
        wordW[s] = right - left;
      });
      // Calm, solid bands behind the names, so the page's own text never runs under them.
      const lineS = S * 1.35;
      if (topBand.current) topBand.current.style.height = `${Math.round(P + keep * lineS + B * 1.15 + P * 0.8)}px`;
      if (bottomBand.current) bottomBand.current.style.height = `${Math.round(P * 0.8 + N * lineS + P)}px`;
      const next = secs.map((el) => el.offsetTop);
      setStarts((old) => (old.length === next.length && old.every((v, i) => v === next[i]) ? old : next));
    }

    let active = -1;
    let hovered = -1;

    // Where a whole name belongs right now: the list at the bottom, the big title, an earlier title, or gone.
    function spot(s: number): Spot {
      const lineS = S * 1.35;
      const room = W - G - P * 1.6;
      const fit = (k: number) => Math.min(k, room / Math.max(1, wordW[s] || 0));
      const shown = Math.max(0, Math.min(keep, active));
      if (!atTop[s]) return { key: "q", rank: 0, k: fit(S / B), y: H - P - (N - 1 - s) * lineS - lineS / 2, a: TONE };
      if (s === active) return { key: `a${shown}`, rank: 1, k: fit(1), y: P + shown * lineS + (B * 1.15) / 2, a: 1 };
      const back = active - s; // 1 = just before the current one
      const gone = back > keep;
      return { key: gone ? "g" : `p${back}:${shown}`, rank: 1 + back, k: fit(S / B), y: P + (shown - back) * lineS + lineS / 2, a: gone ? 0 : TONE };
    }

    function send(s: number, to: Spot, how: "snap" | "forward" | "back" | "settle" | "fade") {
      const right = W - G - P * 0.6;
      const ww = wordW[s] || 0;
      const a = to.a > 0 && to.a < 1 && s === hovered ? 1 : to.a;
      bySection[s].forEach((L) => {
        const x = right - ww * to.k + (L.off + L.w / 2) * to.k;
        const transform = `translate3d(${(x - L.w / 2).toFixed(2)}px,${(to.y - B / 2).toFixed(2)}px,0) scale(${to.k.toFixed(4)})`;
        let t = "none";
        if (how === "forward") t = `transform ${GROW_MS}ms ${GROW_EASE} ${L.i * STAGGER_MS}ms,opacity ${GROW_MS}ms ${GROW_EASE} ${L.i * STAGGER_MS}ms`;
        if (how === "settle") t = `transform ${SETTLE_MS}ms ${GROW_EASE},opacity ${SETTLE_MS}ms ${GROW_EASE}`;
        if (how === "back") t = `transform ${BACK_MS}ms ${BACK_EASE} ${L.i * BACK_STAGGER_MS}ms,opacity ${BACK_MS}ms ${BACK_EASE} ${L.i * BACK_STAGGER_MS}ms`;
        if (how === "fade") {
          // Reduced motion: fade out where it is, jump, fade back in. No movement on screen.
          L.el.style.transition = `opacity ${FADE_MS / 2}ms linear`;
          L.el.style.opacity = "0";
          timers.push(
            window.setTimeout(() => {
              L.el.style.transition = "none";
              L.el.style.transform = transform;
              void L.el.offsetWidth;
              L.el.style.transition = `opacity ${FADE_MS / 2}ms linear`;
              L.el.style.opacity = String(a);
            }, FADE_MS / 2),
          );
          return;
        }
        L.el.style.transition = t;
        L.el.style.transform = transform;
        L.el.style.opacity = String(a);
      });
    }

    // Light a gray name (or let it go) without moving it.
    function light(s: number, on: boolean) {
      const to = placed[s];
      if (!to || to.a <= 0 || to.a >= 1) return;
      const ms = on ? LIT_IN_MS : LIT_OUT_MS;
      bySection[s].forEach((L) => {
        const keepMove = L.el.style.transition.includes("transform") ? L.el.style.transition.split(",opacity")[0] + "," : "";
        L.el.style.transition = `${keepMove}opacity ${ms}ms ease`;
        L.el.style.opacity = String(on ? 1 : to.a);
      });
    }

    function placeHits() {
      const right = W - G - P * 0.6;
      hits.forEach((hit, s) => {
        const to = placed[s];
        const on = !!to && to.a > 0;
        hit.toggleAttribute("data-on", on);
        if (!on) return;
        const w = (wordW[s] || 0) * to.k;
        const h = Math.max(B * to.k * 1.2, 20);
        hit.style.width = `${w + 8}px`;
        hit.style.height = `${h}px`;
        hit.style.transform = `translate(${(right - w - 4).toFixed(1)}px,${(to.y - h / 2).toFixed(1)}px)`;
      });
    }

    let raf = 0;
    let first = true;

    function update(relayout: boolean) {
      raf = 0;
      const o = overlay!.getBoundingClientRect();
      for (let s = 0; s < N; s++) {
        const top = (tops[s] = secs[s].getBoundingClientRect().top - o.top);
        atTop[s] = top <= TOP_AT + (atTop[s] ? GIVE : 0);
      }
      active = -1;
      for (let s = 0; s < N; s++) if (atTop[s]) active = s;

      let moved = false;
      for (let s = 0; s < N; s++) {
        const to = spot(s);
        const was = placed[s];
        // First paint, or a new size with the name still in the same place: put it there at once.
        if (first || !was || (relayout && was.key === to.key)) {
          send(s, to, "snap");
          placed[s] = to;
          moved = true;
          continue;
        }
        if (was.key === to.key) continue;
        const how = reduce.matches ? "fade" : to.rank > was.rank ? (was.rank === 0 ? "forward" : "settle") : "back";
        send(s, to, how);
        placed[s] = to;
        moved = true;
      }
      if (moved) {
        placeHits();
        // The bottom band holds only the names still waiting, and eases down as they leave.
        const waiting = atTop.filter((t) => !t).length;
        const band = bottomBand.current;
        if (band) {
          const lineS = S * 1.35;
          const gone = waiting ? (N - waiting) * lineS : N * lineS + P * 2 + 2;
          const grow = waiting > (band.dataset.n ? Number(band.dataset.n) : waiting);
          band.style.transition = first || relayout || reduce.matches ? "none" : grow ? `transform ${BACK_MS}ms ${BACK_EASE}` : `transform ${SETTLE_MS}ms ${GROW_EASE}`;
          band.style.transform = `translateY(${gone.toFixed(1)}px)`;
          band.dataset.n = String(waiting);
        }
      }

      if (markRef.current) {
        let pr = 0;
        if (own) {
          const max = root!.scrollHeight - root!.clientHeight;
          pr = max > 0 ? root!.scrollTop / max : 0;
        } else {
          const r = root!.getBoundingClientRect();
          const max = r.height - innerHeight;
          pr = max > 0 ? Math.min(1, Math.max(0, -r.top / max)) : 0;
        }
        const y = P + pr * Math.max(0, H - 2 * P - 16);
        markRef.current.style.transform = `translateY(${y.toFixed(1)}px)`;
        if (labelRef.current) labelRef.current.textContent = N ? `${two(Math.max(0, active) + 1)}/${two(N)}` : "00/00";
        // A section's number steps aside while the reading passes over it, so the two never overlap.
        nums().forEach((b, s) => b.toggleAttribute("data-hide", Math.abs(tops[s] - (y + 9)) < 16));
      }

      if (first) {
        first = false;
        overlay!.setAttribute("data-ready", "");
      }
    }

    const kick = () => {
      if (!raf) raf = requestAnimationFrame(() => update(false));
    };
    const relayout = () => {
      measure();
      cancelAnimationFrame(raf);
      update(true);
    };

    // A click on a name glides the page to that section: a calm, eased glide (the browser's own
    // smooth scroll is quick and abrupt). A wheel, touch or key from the visitor stops it at once.
    let glide = 0;
    const stopGlide = () => {
      cancelAnimationFrame(glide);
      glide = 0;
    };
    const jump = (s: number) => {
      stopGlide();
      const from = own ? root.scrollTop : scrollY;
      const to = own ? content.offsetTop + secs[s].offsetTop : scrollY + secs[s].getBoundingClientRect().top;
      const go = (y: number) => (own ? (root.scrollTop = y) : window.scrollTo(0, y));
      if (reduce.matches || Math.abs(to - from) < 2) return void go(to);
      const dur = Math.min(GLIDE_MAX, Math.max(GLIDE_MIN, Math.abs(to - from) * GLIDE_PER_PX));
      const t0 = performance.now();
      const ease = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2);
      const step = (now: number) => {
        const t = Math.min(1, (now - t0) / dur);
        go(from + (to - from) * ease(t));
        glide = t < 1 ? requestAnimationFrame(step) : 0;
      };
      glide = requestAnimationFrame(step);
    };
    const userScroll: (keyof HTMLElementEventMap)[] = ["wheel", "touchstart", "keydown", "pointerdown"];
    const glideTarget: HTMLElement | Window = own ? root : window;
    userScroll.forEach((e) => glideTarget.addEventListener(e, stopGlide, { passive: true }));
    const offs = hits.map((hit, s) => {
      const click = (e: MouseEvent) => {
        e.stopPropagation();
        jump(s);
      };
      const enter = () => {
        if (!canHover.matches) return;
        hovered = s;
        light(s, true);
      };
      const leave = () => {
        if (hovered === s) hovered = -1;
        light(s, false);
      };
      hit.addEventListener("click", click);
      hit.addEventListener("pointerenter", enter);
      hit.addEventListener("pointerleave", leave);
      return () => {
        hit.removeEventListener("click", click);
        hit.removeEventListener("pointerenter", enter);
        hit.removeEventListener("pointerleave", leave);
      };
    });

    measure();
    update(true);
    const scroller: HTMLElement | Window = own ? root : window;
    scroller.addEventListener("scroll", kick, { passive: true });
    const ro = new ResizeObserver(relayout);
    ro.observe(root);
    ro.observe(content);
    let alive = true;
    document.fonts?.ready.then(() => {
      if (alive) relayout();
    });

    return () => {
      alive = false;
      cancelAnimationFrame(raf);
      stopGlide();
      userScroll.forEach((e) => glideTarget.removeEventListener(e, stopGlide));
      timers.forEach(clearTimeout);
      offs.forEach((off) => off());
      scroller.removeEventListener("scroll", kick);
      ro.disconnect();
    };
    // `words` follows `sig`; the rest are settings that rebuild the scene
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [sig, keep, own]);

  const vars = { "--srl-h": own ? cssLength(height!) : "100dvh" } as CSSProperties;

  return (
    <div
      ref={rootRef}
      className={["srl", className].filter(Boolean).join(" ")}
      data-own={own ? "" : undefined}
      role={own ? "region" : undefined}
      aria-label={own ? ariaLabel : undefined}
      tabIndex={own ? 0 : undefined}
      style={{ ...vars, ...style }}
    >
      <style href="impeccable-section-rail" precedence="default">
        {CSS}
      </style>

      <div ref={overlayRef} className="srl-o" aria-hidden="true">
        <div ref={topBand} className="srl-band" data-at="top" />
        <div ref={bottomBand} className="srl-band" data-at="bottom" />
        {words.map((w, s) => (
          <span key={`m${s}`} className="srl-m">
            {w.map((ch, i) => (
              <span key={i}>{ch}</span>
            ))}
          </span>
        ))}
        {words.map((w, s) =>
          w.map((ch, i) => (
            <span key={`${s}-${i}`} className="srl-f" data-s={s} data-i={i}>
              {ch}
            </span>
          )),
        )}
        {sections.map((_, s) => (
          <button key={`h${s}`} type="button" className="srl-hit" tabIndex={-1} aria-hidden="true" />
        ))}
        {ruler && (
          <div ref={markRef} className="srl-mark">
            <span ref={labelRef}>
              {sections.length ? "01" : "00"}/{two(sections.length)}
            </span>
          </div>
        )}
      </div>

      <div ref={contentRef} className="srl-c">
        {ruler && (
          <div className="srl-r" aria-hidden="true">
            {starts.map((top, s) => (
              <span key={s} style={{ display: "contents" }}>
                <i style={{ top }} />
                <b style={{ top }}>{two(s + 1)}</b>
              </span>
            ))}
          </div>
        )}
        {sections.map((sec, s) => (
          <section key={s} id={sec.id} className="srl-s">
            <h2 className="srl-sr">{sec.title}</h2>
            {sec.content}
          </section>
        ))}
      </div>
    </div>
  );
}
```

Usage

Pass your sections to sections, each with a short title. Leave out height on a long page, so it follows the page scroll. Short titles of one or two words read best as the big title.

"use client";
import { SectionRail } from "@/components/ui/section-rail";

// Each section has a name and what it holds. Leave out height and it follows the page scroll.
export function Story() {
  return (
    <SectionRail
      sections={[
        { title: "Intro", content: <Intro /> },
        { title: "Features", content: <Features /> },
        { title: "Pricing", content: <Pricing />, id: "pricing" },
        { title: "Get started", content: <GetStarted /> },
      ]}
    />
  );
}

// Or give it a height to make it its own scroll box.
// <SectionRail sections={sections} height={560} aria-label="Our story" />

How it moves

Every name has two places: the small gray list at the bottom, and the title at the top. Both sit on calm, solid bands, so your own text never runs under them.

When a section's top reaches the top of the view, its name rises from the gray list and grows to the big, full-strength title in 1.4 seconds. It starts softly, never jumps, and settles with a long, gentle landing, and its letters start 32ms apart, left to right, so the word grows like a soft wave. At the same time the title before it eases down to the small gray size in 1.1 seconds and sits above it; two earlier titles stay, older ones fade away. Scroll back up and every move reverses, a little quicker, in 0.6 seconds. A gray name you point at turns full strength, and a click glides the page to that section in 0.9 to 1.7 seconds, depending on how far it goes; a wheel or touch from you stops the glide at once. Every move is a CSS transition on transform and opacity only, so the browser runs it smoothly. With reduced motion nothing moves: each name fades out and back in at its new place in 0.22 seconds.

Props

PropDefaultWhat it does
sections—The sections, top to bottom: { title, content, id? }. The title is shown in capitals; write it as normal.
height—Makes it its own scroll box this tall: 560 (px) or any CSS length like "70vh". Leave it out to follow the page scroll.
keep2How many earlier titles stay above the current one. Older ones fade away.
rulertrueThe thin ruler at the right edge: tick marks, a numbered mark where each section starts, and the line that reads 02/05.
aria-label"Sections"Name of the scroll box for screen readers, only with a height. Each section also gets its title as a hidden heading.
className / style—On the outer box. Colors come from --foreground and --background (or --fg and --bg), so it follows your theme.