Skip to documentation content

Scroll Progress

A thin bar that fills as the page or a scroll container is read, smoothed with a spring.

scroll-progress-demo

Overview

Scroll Progress shows how far through a long page or panel the reader is. It tracks the page by default and sits fixed at the top of the viewport. Pass a container ref to track a scrolling element instead; the bar then sticks to the top or bottom of that element.

The bar scales from the left edge, which animates on the compositor and stays smooth during fast scrolling. A spring adds a little weight to the motion; it is turned off under reduced motion so the bar tracks scrolling exactly.

Installation

npx honestui@latest add scroll-progress

Usage

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

// Track the page
<ScrollProgress />

// Track a scroll container: render the bar as its first child
const ref = useRef<HTMLDivElement>(null)

<div ref={ref} className="h-96 overflow-y-auto">
  <ScrollProgress container={ref} />
  {/* content */}
</div>

Set the color and thickness with className, for example h-1 bg-primary. Inside a container, the bar cancels its own default height with a negative margin so content does not shift; if you change the height, adjust the margin to match.

Accessibility

The bar is decorative and hidden from assistive technology, because the scroll position is already available to people using a screen reader or keyboard. If reading progress matters to the task, such as a required agreement, state it in text as well.

API Reference

PropTypeDefaultDescription
containerRefObject<HTMLElement | null>–Scroll container to track. Omit to track the page.
positiontop|bottom"top"Edge the bar sits on.
smoothbooleantrueSmooth the bar with a spring. Ignored under reduced motion.
classNamestring–Classes for the bar, such as its height and color.