SMALL DETAIL · BETTER EXPERIENCE
Scroll to Top Button
Scroll down the page. A red button will appear in the bottom-right corner. Click it to smoothly return to the top.
Explore the page ↓Scroll Down The Page
A simple back-to-top control helps visitors navigate long pages without manually scrolling all the way back.
Why use a back-to-top button?
Long-form pages, documentation, product catalogs and editorial websites can require a lot of scrolling. A small fixed control gives visitors a quick way to return to the beginning.
The button stays out of the way near the bottom-right edge. It becomes visible after the visitor scrolls down and fades away again near the top.
JavaScript listens for the page scroll event and checks the current vertical scroll position. When the position passes the chosen threshold, a visible class is added to the button.
How it works
The button is fixed to the viewport using CSS. Its opacity and visibility are transitioned so that it can fade smoothly in and out. The click handler uses the browser's smooth scrolling API to return to the top.
The original tutorial also demonstrates the cross-browser scroll position reset: document.body.scrollTop = 0 for Safari and document.documentElement.scrollTop = 0 for Chrome, Firefox and Opera.
Keep exploring
This sample article intentionally includes enough content to demonstrate the interaction. Resize the browser to see the layout adapt to smaller screens. The fixed button remains accessible and stays in the same viewport position.
Good interface details should be easy to discover, work reliably, and avoid distracting from the content. A compact back-to-top button is a useful example of that principle.