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.
smoothclassNameimport { useRef, type ReactNode } from "react"
import { ScrollProgress } from "@/components/ui/scroll-progress"
export function Reader({ children }: { children: ReactNode }) {
const scrollport = useRef<HTMLDivElement>(null)
return (
<div className="overflow-hidden rounded-lg border">
<ScrollProgress containerRef={scrollport} fixed={false} />
<div ref={scrollport} className="h-56 overflow-y-auto p-4">
{children}
</div>
</div>
)
}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.
import { ScrollProgress } from '@/components/ui/scroll-progress';
export function Example() {
// Tracks the page, pinned to the top of the viewport.
return <ScrollProgress />;
}Smoothed
1:1
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.
import { useRef } from 'react';
import { ScrollProgress } from '@/components/ui/scroll-progress';
export function Example() {
const scrollport = useRef<HTMLDivElement>(null);
return (
<>
<ScrollProgress containerRef={scrollport} fixed={false} />
<ScrollProgress containerRef={scrollport} fixed={false} smooth={false} />
<article ref={scrollport} className="h-56 overflow-y-auto">
{children}
</article>
</>
);
}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.
import { ScrollProgress } from '@/components/ui/scroll-progress';
export function Example() {
return (
<ScrollProgress className="h-1 bg-gradient-to-r from-primary to-primary/40" />
);
}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
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>.