Back to PrequelUIYou are on Scroll Progress.

Scroll Progress

A scroll-linked progress bar driven without overshoot.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
scroll-progress.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/scroll-progress.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/scroll-progress.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
scroll-progress.tsx
"use client";

import * as React from "react";
import { motion, useMotionValue, useSpring, type Transition } from "motion/react";
import { cn } from "@/lib/utils";
import { scrollSpring, useTempoTransition } from "./motion";

export type ScrollProgressProps = React.HTMLAttributes<HTMLDivElement> & {
  containerRef?: React.RefObject<HTMLElement | null>;
  barClassName?: string;
  transition?: Transition;
};

export function ScrollProgress({
  containerRef,
  barClassName,
  transition,
  className,
  ...props
}: ScrollProgressProps) {
  const progress = useMotionValue(0);
  const spring = useTempoTransition(transition ?? scrollSpring);
  const smooth = useSpring(progress, spring);

  React.useEffect(() => {
    const target = containerRef?.current;
    const read = () => {
      if (target) {
        const max = target.scrollHeight - target.clientHeight;
        progress.set(max > 0 ? Math.min(1, Math.max(0, target.scrollTop / max)) : 0);
      } else {
        const max = document.documentElement.scrollHeight - window.innerHeight;
        progress.set(max > 0 ? Math.min(1, Math.max(0, window.scrollY / max)) : 0);
      }
    };
    read();
    const node: HTMLElement | Window = target ?? window;
    node.addEventListener("scroll", read, { passive: true });
    window.addEventListener("resize", read);
    return () => {
      node.removeEventListener("scroll", read);
      window.removeEventListener("resize", read);
    };
  }, [containerRef, progress]);

  return (
    <div
      role="progressbar"
      aria-label="Scroll progress"
      data-slot="scroll-progress"
      className={cn("h-1 w-full overflow-hidden bg-accent", className)}
      {...props}
    >
      <motion.div
        style={{ scaleX: smooth }}
        className={cn("h-full origin-left bg-foreground", barClassName)}
      />
    </div>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/scroll-progress.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

scroll-progress.tsx
import { useRef } from "react";
import { ScrollProgress } from "@/components/prequelui/scroll-progress";

export default function Demo() {
  const ref = useRef<HTMLDivElement>(null);
  return (
    <div className="w-[320px]">
      <ScrollProgress containerRef={ref} />
      <div ref={ref} className="h-40 overflow-y-auto">
        {/* long content */}
      </div>
    </div>
  );
}
import { ScrollProgress } from "@/components/prequelui/scroll-progress";

export function Variant() {
  return (
    <ScrollProgress tempo={1.2}>
      …
    </ScrollProgress>
  );
}
03

Animation

The bar follows a container or the page through a spring that is damped to zero bounce. Scroll events only write the raw ratio; the spring is what gives the bar its short, smooth catch-up.

  • Spring: 250 / 40 with bounce 0.
  • A ref target measures its own scroll range; no ref targets the page.
  • The bar scales on X from a left origin, never animating width.
  • A resize listener re-measures the range.
  • Scroll updates are passive and never block the page.
spring 250 / 40bounce 0scaleXpassive scroll
04

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

ScrollProgress

PropTypeDefault
containerRefRefObject<HTMLElement>—
barClassNamestring—
transitionTransitioncomponent spring or tween
classNamestring—

Next component

Spring

A draggable element tied to its home by a visible spring.