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().

  • scroll-driven
  • reading progress
  • animation-timeline
  • scroll
  • indicator
  • blog
HTML
<div class="scroll-progress" aria-hidden="true"></div>
CSS
.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

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:

CSS
@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

  1. Copy the HTML and paste it where you want the element to appear.
  2. Copy the CSS into your stylesheet, or inside a <style> tag.
  3. Keep the .scroll-progress class name, or rename it in both places. Then tweak colors, sizes and timing to match your design.
  4. Using React or Next.js? Change class to className in 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.

Feedback