Scroll Progress

Animated

A thin bar that fills as a page or container scrolls.

Source
$npx @dinachi/cli@latest add scroll-progress

A progress bar earns its place on long-form content, where the scrollbar alone is not much of an answer to how much is left.

It tracks the page by default. An app that scrolls an inner element rather than the document leaves the bar at zero until it is pointed at that element.

The spring is short enough that the bar never visibly disagrees with the text on screen, and it never overshoots: claiming progress the reader has not made would be worse than lagging.

Under a reduced-motion preference the spring is dropped and the bar tracks scroll one to one. It still moves, because that movement is the reader's own gesture.

smooth
className

Usage

import { ScrollProgress } from "@/components/ui/scroll-progress"

export function Article() {
  return <ScrollProgress />
}

Examples

A progress bar earns its place on long-form content, where the scrollbar alone is not much of an answer to how much is left.

It tracks the page by default. An app that scrolls an inner element rather than the document leaves the bar at zero until it is pointed at that element.

The spring is short enough that the bar never visibly disagrees with the text on screen, and it never overshoots: claiming progress the reader has not made would be worse than lagging.

Under a reduced-motion preference the spring is dropped and the bar tracks scroll one to one. It still moves, because that movement is the reader's own gesture.

How far a scroll container has been read.
import { ScrollProgress } from '@/components/ui/scroll-progress';

export function Example() {
  // Tracks the page, pinned to the top of the viewport.
  return <ScrollProgress />;
}

Notes

Motion tier

Needs motion. add --all skips it; install with add --motion or by name.

When to use it

  • Articles, changelogs and documentation pages.
  • Skip it on short pages.

Scroll containers

When an inner element scrolls instead of the document, point the bar at it or it stays at zero.

const scrollport = useRef<HTMLDivElement>(null)

<ScrollProgress containerRef={scrollport} fixed={false} />
<article ref={scrollport} className="overflow-y-auto">…</article>

A CSS selector also works, for layouts with no ref available. A selector that matches nothing falls back to the page without throwing.

<ScrollProgress containerRef="#reader" />

Behaviour

  • Tracks vertical scroll only.
  • The spring is critically damped, so it never overshoots.

API

containerRefRefObject<HTMLElement> | string
Container to track: a ref or CSS selector. Omit to track the page.
smoothboolean = true
Smooths the bar with a spring. False tracks 1:1.
fixedboolean = true
Pins the bar to the top of the viewport. False to place it yourself.
classNamestring
Height, colour and position. Defaults to h-0.5 bg-primary.

Accessibility

  • The bar is aria-hidden; the scrollbar already exposes progress.
  • A fixed bar has pointer-events-none, so it never blocks clicks.
  • Reduced motion drops the spring and tracks scroll 1:1.
  • Honours an app-level <MotionConfig reducedMotion>.