Back-to-Top Button
A floating button that appears on scroll and returns to the top.
Requires Bootstrap 5. Add the CDN tags below to your page (styles in
<head>, scripts before </body>). The downloaded file already includes them.<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script><div style="max-width:340px"><div class="border rounded-3 overflow-auto position-relative p-3 small text-secondary" id="btScroll" style="height:240px">
<h6>Long content</h6><p>Scroll down to reveal the back-to-top button.</p><div style="height:200px"></div><p>More content here.</p><div style="height:200px"></div><p>Bottom.</p>
<button class="btn btn-primary rounded-circle position-sticky shadow" id="btBtn" style="bottom:10px;left:100%;width:42px;height:42px;display:none">↑</button>
</div></div>var sc=document.getElementById('btScroll'),btn=document.getElementById('btBtn');
sc.addEventListener('scroll',function(){btn.style.display=sc.scrollTop>120?'inline-block':'none'});
btn.onclick=function(){sc.scrollTo({top:0,behavior:'smooth'})};Free to use.This component uses Bootstrap 5 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.