Style Library
Scroll Progress
AnimationanimationAnimated scroll progress for your web pages.
Prompt
Paste into any AI assistant before describing what to build — or attach it to a project below.
# Animation pattern — Scroll Progress
Animated scroll progress for your web pages.
Build it in React with `motion` (motion/react) and Tailwind CSS. Respect `prefers-reduced-motion` (render the final state without movement), keep it under ~400 ms for UI feedback, and animate only transform and opacity where possible.
Reference implementation (Motion-Primitives, MIT):
```tsx
'use client';
import { motion, SpringOptions, useScroll, useSpring } from 'motion/react';
import { cn } from '@/lib/utils';
import { RefObject } from 'react';
export type ScrollProgressProps = {
className?: string;
springOptions?: SpringOptions;
containerRef?: RefObject<HTMLDivElement>;
};
const DEFAULT_SPRING_OPTIONS: SpringOptions = {
stiffness: 200,
damping: 50,
restDelta: 0.001,
};
export function ScrollProgress({
className,
springOptions,
containerRef,
}: ScrollProgressProps) {
const { scrollYProgress } = useScroll({
container: containerRef,
layoutEffect: Boolean(containerRef?.current),
});
const scaleX = useSpring(scrollYProgress, {
...DEFAULT_SPRING_OPTIONS,
...(springOptions ?? {}),
});
return (
<motion.div
className={cn('inset-x-0 top-0 h-1 origin-left', className)}
style={{
scaleX,
}}
/>
);
}
```Use it in an app
Create a free account to attach this style to a project: the hub adds it to the prompt your AI assistant gets, so it builds every page in this look.
From Motion-Primitives (MIT, commit 120f64f).View source