Scroll Progress

A reading progress bar or ring that follows how far the page has scrolled.

Preview

"use client";

import { useScroll } from "motion/react";
import { useRef } from "react";

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

// Real usage: drop <ScrollProgress /> anywhere — it reads page scroll via
// useSmoothScroll and pins itself with `fixed`. Here we scope it to a box by
// passing a contained `progress` source and `fixed={false}`.
const SECTIONS = Array.from({ length: 18 }, (_, i) => i + 1);

export function ScrollProgressPreview() {
  const ref = useRef<HTMLDivElement>(null);
  const { scrollYProgress } = useScroll({ container: ref });

  return (
    <div className="relative w-full max-w-lg overflow-hidden rounded-2xl border border-border bg-card">
      <ScrollProgress progress={scrollYProgress} fixed={false} height={3} />
      <div className="absolute right-3 top-3 z-10 rounded-full bg-background/70 p-1 backdrop-blur">
        <ScrollProgress variant="circle" progress={scrollYProgress} size={36} />
      </div>
      <div ref={ref} className="h-64 overflow-y-auto scrollbar-hide">
        <div className="space-y-3 p-4">
          {SECTIONS.map((n) => (
            <div
              key={`row-${n}`}
              className="rounded-2xl bg-muted/60 px-3 py-4 text-sm text-muted-foreground"
            >
              Section {n}
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/scroll-progress

API Reference

variant?
"bar" | "circle"

A thin horizontal bar, or "circle" for a ring. Default: "bar"

Default—
position?
"top" | "bottom"

Edge the bar sits on. Default: "top"

Default—
height?
number

Bar thickness in px.

Default—
fixed?
boolean

Position the bar with `fixed` (page) or `absolute` (embedded).

Default—
progress?
MotionValue<number>

Override the scroll source. Defaults to the page via useSmoothScroll.

Default—
spring?
boolean

Spring-smooth the value. Disabled automatically under reduced motion.

Default—
className?
string

Classes merged onto the root element.

Default—
size?
number

Diameter in px.

Default—
thickness?
number

Stroke width in px.

Default—

More in Scroll Animation

Updated