Scroll Progress

Ruler-style section index that marks each heading, tracks the reader's position, and jumps or scrubs to any section.

Scroll Progress

Ruler-style section index that marks each heading, tracks the reader's position, and jumps or scrubs to any section.

The preview runs in self mode, so the card scrolls on its own instead of the page. Scroll it to watch the head ride the rail between ticks, hover to swell the ticks near the pointer and name each section, click anywhere on the rail to jump to the nearest heading, or drag it to scrub through the content. Switching to scroller="window" lets the page scroll and docks the same rail beside your content.

Installation

Install the component with the Craft-UI Blocks CLI — it drops scroll-progress.tsx into your project and wires up its runtime dependencies:

npx mvpblocks add scroll-progress
pnpm dlx mvpblocks add scroll-progress
yarn dlx mvpblocks add scroll-progress
bunx mvpblocks add scroll-progress

File Structure

The CLI saves the component to your project's components/ui folder:

Import the default export from @/components/ui/scroll-progress. The component itself is named ScrollIndex, and its prop type is exported as ScrollIndexProps.

Usage

ScrollIndex is a client component. Drop your article in as children and every h2 / h3 inside it becomes a tick:

"use client";

import ScrollIndex from "@/components/ui/scroll-progress";

export function Notes() {
  return (
    <ScrollIndex>
      <article className="mx-auto max-w-xl">
        <h2>Building a component library</h2>
        <p>
          A component library is a promise: that the next screen will be faster
          to build than the last.
        </p>

        <h3>Restraint</h3>
        <p>Ship the smallest component that solves the problem in front of you.</p>

        <h2>Tokens</h2>
        <p>Color, type, spacing and radius live in one place.</p>
      </article>
    </ScrollIndex>
  );
}

Omit children and the component renders a built-in sample article — useful for trying the rail without wiring any content. In self mode the content wrapper already supplies its own padding (py-8 pr-16 pl-6 sm:pl-10), so don't add a second outer padding to your article. To change the fixed box height, pass a height class through className — the cn merge replaces the default h-[520px].

Track the page instead of the component's box by setting scroller="window". The rail moves into a sticky 3rem column beside the content and follows the page scroll:

"use client";

import ScrollIndex from "@/components/ui/scroll-progress";

export function DocsPage() {
  return (
    <ScrollIndex scroller="window">
      <article className="mx-auto max-w-2xl">
        {/* the same article markup as above */}
      </article>
    </ScrollIndex>
  );
}

Change which headings get a tick with selector. The tag number also sets the tick's weight — h2 and above draw wider than h3 and below:

<ScrollIndex selector="h1, h2, h3, h4">{/* content */}</ScrollIndex>

Theming

The rail ships with an exact zinc palette rather than theme tokens, so it reads the same in light and dark mode without configuration. In self mode the wrapper is a rounded-2xl card with border-zinc-200 bg-white that inverts to dark:border-zinc-800 dark:bg-zinc-950, fixed at 520px tall. Ticks are bg-zinc-300 (dark:bg-zinc-700) while ahead, bg-zinc-900 (dark:bg-zinc-100) once passed, and bg-blue-500 (dark:bg-blue-400) for the section being read; keyboard focus adds a ring-zinc-400 outline. The reading head is a 2px bg-zinc-900 (dark:bg-zinc-100) bar, and the section label is a small white / zinc-900 card with a zinc-200 / zinc-800 border and zinc-700 / zinc-200 text. The built-in sample article uses zinc-900 headings, zinc-600 body copy, and zinc-400 / zinc-500 eyebrow text, all inverting in dark mode.

The tick line is 1.5px tall and scales from its right edge with --swell, so the dock effect never shifts the rail's alignment. h2 ticks get a w-3.5 (14px) line, h3 and deeper get w-2 (8px).

Animations

  • Reading head: the bar is written directly to the DOM with translate3d from a single requestAnimationFrame loop, so it tracks the scroll fraction between ticks continuously and never waits on React.
  • Tick dock: near the pointer, ticks add up to 1.6x their width (a 2.6x peak scale) with a Gaussian falloff over a 26px reach. Each tick eases 35% of the remaining distance to its target every frame, so magnification follows the pointer smoothly instead of snapping; the swell resets when the pointer leaves.
  • Section flash: scrolling into a new section briefly shows its name for 900ms. Hovering, focusing, or dragging keeps the label up, and the hide timer skips while any of those is active, so the label never disappears under the pointer.
  • Jump tween: clicking a tick (or the rail) scrolls with a quart ease-in-out over 300–650ms, scaled by distance (260 + distance × 0.12, clamped). A wheel or touchstart from the reader cancels the tween immediately, so a jump never fights the user's own scrolling.
  • Drag and snap: dragging the rail scrubs the scroll position directly. On release, the pointer's velocity is projected 120ms ahead and the nearest tick is snapped to — after a drag, only if that tick is within 18px, so a short flick lands on a section instead of between two. A plain click always jumps to the nearest tick.
  • Reduced motion: under prefers-reduced-motion jumps become instant and the dock swell is disabled, while the reading head and section naming still work.

How it works

On mount the component measures the content and every heading matching selector, then maps each heading's scroll position onto the 280px rail as a fraction from 0 to 1. Ticks are absolutely positioned by that fraction, so long sections leave long gaps and short sections cluster — the rail is a map of the document, not an evenly spaced list. A heading lands 16px below the top edge when jumped to.

In self mode the scroll range is the box's own scrollHeight - clientHeight, and the rail sits absolutely at the right edge. In window mode the range starts at the content's top offset (16px above it, clamped to 0) and ends where the content's bottom meets the viewport, while the rail sticks at calc(50vh - 140px).

The active section is the last heading at or above the current scroll position. Scrolling, resizing (through a ResizeObserver on the content and the box), hovering, and dragging all funnel into the same frame scheduler, which writes the head position, tick states, and label without re-rendering React. Only re-measuring updates the sections state that renders the tick buttons.

Each tick is a real button with its heading as aria-label. The rail keeps a single tab stop on the active tick and aria-current="location" on it, while ArrowUp / ArrowDown move focus between ticks. Focusing a tick reveals its label; pressing Enter or Space jumps to that section. Pointer clicks are handled by the rail itself so a click anywhere on the rail selects the nearest section.

Props

Prop

Type

Registry Bundle

Install the exact registry entry shown on the right when you want the component file and its declared runtime dependencies together. Dependencies: none — the index ships with no runtime packages beyond React.

Contact

If you find any bug or issue, feel free to raise an issue.

Last updated on