CSS Scroll Progress Bar
A reading progress bar pinned to the top of the page that fills as you scroll, driven by animation-timeline: scroll().
<div class="scroll-progress" aria-hidden="true"></div>
.scroll-progress {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: 100;
height: 4px;
background: linear-gradient(90deg, #6366f1, #ec4899);
transform-origin: 0 50%;
animation: scroll-progress-grow linear both;
animation-timeline: scroll();
}
@keyframes scroll-progress-grow {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
@supports not (animation-timeline: scroll()) {
.scroll-progress {
display: none;
}
}
About this CSS Scroll Progress Bar
This CSS Scroll Progress Bar is 28 lines of pure CSS (0.5 KB) with no JavaScript and no dependencies. It uses scroll-driven animations, keyframe animations, transforms and linear gradients. It relies on scroll-driven animations, which not every browser supports yet, so check the browser notes below. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
- scroll-driven animationsChrome and Edge 115+ and Safari 26+. Firefox support is very recent; browsers without it skip the animation and show the content as is.
- keyframe animations
- transforms
- linear gradients
Customize it
The colors in this snippet. Search and replace them to match your brand:
#6366f1#ec4899
Accessibility
This snippet animates. Add this rule so people who turn on “reduce motion” in their system settings get a still version:
@media (prefers-reduced-motion: reduce) {
.scroll-progress,
.scroll-progress *,
.scroll-progress::before,
.scroll-progress::after {
animation: none !important;
}
}How to use this scroll progress bar
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.scroll-progressclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.