If you need a plain JavaScript function to add a smooth scrolling back to the top of the page, you can use this script:
window.scrollTo({top: 0, behavior: "smooth"});
How? 👉 Just add this script to a <button>
element in the onclick:
attribute, like this (and place it at the bottom of your page):
<button onclick='window.scrollTo({top: 0, behavior: "smooth"});'>Back to Top ↑</button>
CodePen demo here: (https://codepen.io/ricardozea/pen/NWpgyjL) by Ricardo Zea on CodePen.
You can use the
border-radius
property in thebutton
class. Check out the demo in CodePen, you can play with the CSS there without affecting the final output. You can also fork the demo and play with it and save the changes for yourself.