Skip to content

Back to Top Button with Scroll Progress

Round back-to-top button with an SVG ring that fills as you scroll, a percentage label and smooth scrolling, for the page or any scroll container.

Also known as: scroll to top button, scroll progress indicator, back to top with progress, floating top button

Back to Top Button with Scroll Progress live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A round back-to-top button with a circular scroll progress ring, built with pure CSS, an inline SVG and a few lines of vanilla JavaScript. The ring fills as the reader moves down the page and a small percentage label sits under the arrow. It suits blogs, documentation, long landing pages and any scrollable panel.

How it works

The component is a single button.bt-top. Inside it, svg.bt-ring draws two circles: .bt-track is the faint full ring and .bt-meter is the progress arc with a gradient stroke. The meter uses pathLength="100" and stroke-dasharray: 100, so its stroke-dashoffset is simply calc(100 - var(--bt-progress)). The ring is rotated by -90 degrees so it starts at twelve o'clock. .bt-inner holds the arrow icon and .bt-pct.

By default the button is position: fixed in the bottom-right corner and tracks window scrolling. In this demo it is placed in .bt-frame next to the scrollable article.bt-scroll, where it becomes position: absolute and tracks that panel instead.

On DOMContentLoaded the script initializes every .bt-top. It listens for scroll (passive, throttled with requestAnimationFrame) and resize, calculates the scrolled percentage, writes it to --bt-progress and .bt-pct, and adds is-visible once the scroll position passes the threshold. Hidden buttons use visibility: hidden, so they cannot be focused. A click calls scrollTo with smooth behavior and moves focus to the element named in data-bt-focus.

Customization

  • data-bt-target on .bt-top: a CSS selector of a scroll container; remove it to track the whole page.
  • data-bt-show: the number of pixels scrolled before the button appears (default 300); the demo uses 0 so it is always visible.
  • data-bt-focus: selector of the element that receives focus after jumping to the top, such as the main heading with tabindex="-1".
  • --bt-size: the diameter of the button; the ring and icon scale with it.
  • --bt-bg, --bt-fg and --bt-track: the button fill, the arrow and text color, and the unfilled part of the ring.
  • --bt-offset: the distance from the bottom-right corner of the viewport or frame.
  • The two stop-color values in #bt-grad: the gradient of the progress arc.
  • Remove .bt-pct for an icon-only button.

Use cases

  • Blogs: a round button fills as the reader scrolls and jumps smoothly back to the top
  • Documentation sites: the progress ring shows how far through a long page the reader is
  • Long landing pages: the button appears only after a set number of pixels have been scrolled
  • Scrollable panels: it can track any scroll container instead of the whole page

Accessibility

The control is a native button, so Enter and Space work. Its aria-label is updated to read, for example, "Back to top, 42% scrolled", while the icon and visible percentage are aria-hidden. After the jump, focus moves to the heading so keyboard and screen reader users continue from the start instead of being left at the bottom. The button and the scrollable article both have visible :focus-visible outlines, and the article has tabindex="0" so it can be scrolled with the keyboard. With prefers-reduced-motion: reduce the page jumps instantly and all transitions are removed.

Usage notes

For a site-wide button, copy only .bt-top and its styles, drop data-bt-target and place it at the end of body. Several buttons can track different containers on one page.

Back to Top Button with Scroll Progress at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile
Category
Back to Top
License
Free for personal and commercial use

Questions about this template

Can I use the Back to Top Button with Scroll Progress code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Back to Top Button with Scroll Progress – free Pure CSS back to top button template
Back to Top Button with Scroll Progress · free Pure CSS back to top button template

More Back to Top

Back to Top Button that Fades In – free Tailwind CSS back to top button template

Back to Top Button that Fades In

Floating Tailwind CSS back-to-top button that fades in after scrolling, smooth-scrolls up and returns keyboard focus to the page title.