ScrollProgress
SM · 950B gzip budgetA reading-progress bar with a real accessible value.
- Category
- Navigation
- Budget
- sm, single-purpose control
- External runtime
- React / React DOM only
axe fixtureSSR rendersource scanbundle budget
Preview
Live fixtureTry the component here. Locale-aware formatting and direction follow the selected language; example content and labels are not automatically translated. Overlay demos use interactive launchers.
Install
npx shadcn@latest add https://gear5-ui.vercel.app/r/scroll-progress.jsonCopies the source into your project. Pulls in 1 shared registry item: cn.
New here? Set up Tailwind and import aliases first →Source & props
Edit on GitHub ↗Prop types and inline documentation are included below. This is repository source; the installer rewrites shared imports for your project.
"use client";
import { useEffect, useState } from "react";
import { cn } from "../lib/cn";
/** A thin bar across the top of the viewport showing reading progress down the page. */
export function ScrollProgress({ className }: { className?: string }) {
const [progress, setProgress] = useState(0);
useEffect(() => {
const onScroll = () => {
const { scrollTop, scrollHeight, clientHeight } = document.documentElement;
const max = scrollHeight - clientHeight;
setProgress(max > 0 ? Math.min(100, (scrollTop / max) * 100) : 0);
};
window.addEventListener("scroll", onScroll, { passive: true });
onScroll();
return () => window.removeEventListener("scroll", onScroll);
}, []);
return (
<div
role="progressbar"
aria-label="Reading progress"
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={Math.round(progress)}
className={cn("fixed inset-x-0 top-0 z-40 h-1 bg-transparent", className)}
>
<div className="h-full bg-blue-600 transition-[width] duration-150 motion-reduce:transition-none" style={{ width: `${progress}%` }} />
</div>
);
}
What CI checks
Quality contract- Bundled, minified and gzipped against its tier budget
- Audited by axe in the state previewed above
- Rendered through react-dom/server with no browser globals
- Scanned for network calls, dangerous sinks, and unguarded animation