Scroll Progress Bar

Reading progress bar fixed to top of page.

Scroll to see it fill. Fixed to viewport top on real pages.

Tailwind CSS
<div class="w-full max-w-md">
  <div class="h-1.5 rounded-full bg-slate-300 overflow-hidden">
    <div class="scroll-progress-fill h-full rounded-full bg-gradient-to-r from-indigo-500 to-purple-500" style="width: 64%"></div>
  </div>
  <p class="mt-2 text-xs text-slate-500 dark:text-slate-400">Scroll to see it fill. Fixed to viewport top on real pages.</p>
</div>
<style>
.scroll-progress-fixed {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 50;
  background: linear-gradient(to right, #6366f1, #a855f7);
  width: 0%;
}
</style>
<script>
(function() {
  var bar = document.createElement('div');
  bar.className = 'scroll-progress-fixed';
  document.body.appendChild(bar);
  window.addEventListener('scroll', function() {
    var h = document.documentElement;
    var pct = h.scrollTop / (h.scrollHeight - h.clientHeight) * 100;
    bar.style.width = pct + '%';
  }, { passive: true });
})();
</script>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Emerald thick

A thicker emerald bar suits content sites with a green brand.

Scroll to see it fill. Fixed to viewport top on real pages.

Tailwind CSS

Bottom bar

Fix the bar to the bottom for mobile apps where top space is precious.

Scroll to see it fill. Fixed to viewport bottom on real pages.

Tailwind CSS

Rose

Rose fits blogs and portfolios with a warm visual identity.

Scroll to see it fill. Fixed to viewport top on real pages.

Tailwind CSS

About this scroll progress bar

Scroll progress bars are the thin line at the top of articles showing how far you have read. Medium made them famous; now they are standard on blogs and documentation. They answer "how much longer is this?" without a single word.

This snippet includes the full implementation: a fixed bar whose width updates on scroll based on scrollTop over total scrollable height. The passive listener keeps it performant. The gradient fill (indigo to purple) is more distinctive than a flat color.

Keep it 3px thin. Thicker bars distract from content. The bar should be purely informational; never put controls in it. On short pages where scrolling is minimal, hide it entirely.

Long articles feel endless, and readers bail on endless things because they can't gauge the commitment. The scroll progress bar turns an infinite-feeling page into a finite task with a single glance at the top edge. It is commitment visualization: knowing 60% is done keeps people reading in a way no intro paragraph can.

The bar is a fixed div: position fixed, top 0, left 0, right 0, height 3px, z-50, with a gradient background. A scroll listener computes scrollTop divided by (scrollHeight minus clientHeight), times 100, and writes it to the bar's width. The listener is passive so it never blocks scrolling, and the width write goes straight to the style, no framework re-render per scroll event.

Keep it 2 to 4px: thicker bars compete with the content for attention. A brand gradient beats a flat color for distinctiveness. Hide it entirely on pages under two viewports, where it would sit full and look broken. On pages with tabbed content, recompute when the active tab changes.

The measurement mistake is reading scrollTop from document.body, which returns 0 in standards mode and leaves the bar permanently empty in some browsers. The correct source is document.documentElement, with a body fallback for quirks mode. It's a one-line bug that makes the whole component look dead.

Where to use it

  • ✓ Blog articles
  • ✓ Documentation pages
  • ✓ Long-form guides
  • ✓ Terms pages

Customization tips

Adjust thickness with height (2-4px). Use your brand gradient. Hide on pages shorter than 2 viewports where progress is meaningless.

Design notes

When to use

A scroll progress bar suits long articles where readers like knowing how much remains, it turns an endless page into a finite one. The thin gradient bar fixed to the viewport top stays visible without stealing space from the content. It works best on reading experiences like guides and documentation rather than on short pages where it fills up instantly.

What to avoid

Do not put a progress bar on pages shorter than two screens, it will sit full and look broken. Avoid thick or brightly pulsing bars that compete with the content for attention, the bar should be felt, not stared at. And do not use it as the only indicator on pages with tabbed content, since scrolling one tab misrepresents the whole.

Accessibility

Hide the bar from screen readers with aria-hidden, it is decorative, and provide the article structure through proper headings instead. Respect prefers-reduced-motion for any animated fill.

Frequently asked questions

How do I make a scroll progress bar?

Add a fixed top bar. On scroll, set its width to scrollTop / (scrollHeight - clientHeight) * 100%. Use a passive scroll listener for performance.

Does scroll progress hurt performance?

Not with a passive listener updating only a width style. Avoid layout-triggering reads in the handler; cache what you can.

Should every page have scroll progress?

No, only long content pages (articles, docs). On short pages it is visual noise. Hide it when the page barely scrolls.

How do I calculate scroll percentage in JavaScript?

Divide window.scrollY by (document.documentElement.scrollHeight - window.innerHeight) and multiply by 100. Update the bar on scroll with a passive listener, ideally throttled through requestAnimationFrame. Set the bar width or scaleX to the resulting percentage.

Can I make a scroll progress bar with only CSS?

Yes, using scroll-driven animations: animate scaleX from 0 to 1 with animation-timeline: scroll() on a fixed top bar. No JavaScript runs at all. Support covers Chromium and Safari, so add a tiny JavaScript fallback for Firefox if your audience needs it.

How do I make a circular scroll progress indicator?

Use an SVG circle and update its stroke-dashoffset on scroll proportionally to the scroll percentage. The circle doubles nicely as a back-to-top button: clicking it smooth-scrolls to the top. Compute the circumference from the radius with 2 * PI * r for the dash values.