How to Create a Circular SVG Scroll Progress Indicator & Smooth Back-to-Top Button

The Quick Answer

A circular scroll indicator calculates scroll ratio as `window.scrollY / (document.documentElement.scrollHeight - window.innerHeight)` and updates an SVG circle's `stroke-dashoffset` (`circumference * (1 - ratio)`). Clicking the button invokes `window.scrollTo({ top: 0, behavior: "smooth" })`.

Interactive Demo Live Preview
🔄 Circular SVG Scroll Meter · Fills from 0% to 100%

Step 1: Construct the Circular SVG Button Markup

Build the circular button container containing background ring, animated progress ring, and up-arrow icon.

scroll-progress-top.html
<button class="scroll-top-btn" id="scrollTopBtn" aria-label="Scroll back to top of page">
  <svg class="progress-ring" viewBox="0 0 48 48">
    <circle class="ring-track" cx="24" cy="24" r="20"></circle>
    <circle class="ring-fill" id="progressCircle" cx="24" cy="24" r="20"></circle>
  </svg>
  <span class="arrow-icon">↑</span>
</button>

Step 2: Apply Circle Dashoffset & Visibility Styling

Rotate the ring -90 degrees so progress begins at 12 o'clock, and fade in smoothly upon scroll.

scroll-progress-top.css
.scroll-top-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: #0f172a;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 950;
}
.scroll-top-btn.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.progress-ring {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}
.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 3;
}
.ring-fill {
  fill: none;
  stroke: #6366f1;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 125.66;
  stroke-dashoffset: 125.66;
  transition: stroke-dashoffset 0.1s linear;
}
.arrow-icon {
  position: relative;
  font-size: 1.2rem;
}

Step 3: Implement the Scroll Progress Calculation

Compute scroll ratio, update stroke-dashoffset, and attach smooth scroll to top listener.

scroll-progress-top.js
const btn = document.getElementById('scrollTopBtn');
const circle = document.getElementById('progressCircle');
const CIRCUMFERENCE = 2 * Math.PI * 20; // ~125.66

function onScroll() {
  const scrollTop = window.scrollY || document.documentElement.scrollTop;
  const docHeight = document.documentElement.scrollHeight - window.innerHeight;
  const progress = Math.min(1, Math.max(0, scrollTop / (docHeight || 1)));

  circle.style.strokeDashoffset = CIRCUMFERENCE * (1 - progress);
  btn.classList.toggle('is-visible', scrollTop > 300);
}

window.addEventListener('scroll', () => {
  requestAnimationFrame(onScroll);
});

btn.addEventListener('click', () => {
  window.scrollTo({ top: 0, behavior: 'smooth' });
});
onScroll();

Next-Level Addons: Elevating Your Implementation

Take this technique further by combining it with complementary design token studios and animation tools:

1. SVG Stroke-Dashoffset Progress Math

Explore in Top Scroll Progress Bar Studio →

Map window.scrollY / documentHeight to SVG circle circumference stroke-dashoffset with zero reflow stutter.

SCROLL TO TOP ↑

2. Smooth Native Scroll-to-Top Easing

Explore in Top Scroll Progress Bar Studio →

Trigger window.scrollTo({ top: 0, behavior: "smooth" }) with automatic prefers-reduced-motion instant fallback.

VISIBLE AFTER > 300px

3. Threshold Visibility Fade (Show after 300px)

Explore in Top Scroll Progress Bar Studio →

Keep the button hidden near page top and smoothly fade it in only when the user has scrolled past 300px.

Chaam
Chaam's Pro Tip

Here's my golden rule when implementing this in production: test across multiple devices and browsers early. Keep your DOM hierarchy shallow, optimize assets with modern formats (like WebP/AVIF), and verify keyboard navigation for accessibility.

Why I Built the Circular Scroll & Back-to-Top Studio

I got tired of guessing values and testing browser quirks in DevTools, so I built this tool to tweak and preview values in real time with 1-click code export.

Open in Circular Scroll & Back-to-Top Studio ↗

Frequently Asked Questions

Practical answers to common implementation questions, browser quirks, and performance tips.

Why does stroke-dashoffset = circumference * (1 - progress) work?

The stroke-dasharray creates a dash pattern equal to the full perimeter (125.66px). Offsetting the dash by 100% hides the line completely; shifting the offset towards 0 reveals the line progressively.

Why use document.documentElement.scrollHeight - window.innerHeight?

Scroll height includes the entire page length. When scrolled to the very bottom, `scrollY` equals `scrollHeight - innerHeight`. Subtracting `innerHeight` ensures progress reaches 100% at the page footer.

Does smooth scrolling work on all browsers?

Yes, `window.scrollTo({ top: 0, behavior: "smooth" })` has over 97% global support across Chrome, Edge, Safari, and Firefox.

Why should the button remain hidden until the user scrolls past 300px?

Showing a back-to-top button at the very top of the page adds visual clutter without any practical utility. Fading in after 300px provides assistance only when needed.

How do you prevent the button from overlapping mobile floating navbars or chat widgets?

Offset the bottom coordinate using safe-area-insets: `bottom: calc(24px + env(safe-area-inset-bottom, 0px));` or elevate above other widgets with z-index.

← Back to all blog guides Launch Generator Studio →