Simple Analytics
css Beginner

CSS Scroll Progress Bar

CSS Scroll Progress Bar
Scroll Progress Bar
Interactive editor — edit code and see live results Open in Editor

How It Works

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #9F7AEA, #ED8936);
  transform-origin: left;
  animation: grow-bar linear;
  animation-timeline: scroll();
}

@keyframes grow-bar {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

Summary

  • animation-timeline: scroll() ties the animation progress to the scroll position of the page instead of a time-based duration.
  • The @keyframes animation scales the bar from scaleX(0) to scaleX(1), visually filling from left to right.
  • transform-origin: left ensures the bar grows from the left edge rather than expanding from the center.
  • This replaces what previously required a scroll event listener, requestAnimationFrame, and manual percentage calculation — all in ~6 lines of CSS.
  • Supported in Chrome 115+ (Jul 2023), Edge 115+, and Safari 18+ (Sep 2024). Firefox: behind flag.

Try this in our interactive code editor

Practice hands-on with our built-in code sandbox.

Open Code Editor
Adrian Bigaj
Adrian Bigaj

Creator of BigDevSoon

Full-stack developer and educator passionate about helping developers build real-world skills through hands-on projects. Creator of BigDevSoon, a vibe coding platform with 21 projects, 100 coding challenges, 40+ practice problems, and Merlin AI.