Vanilla JavaScript and jQuery versions to slide the page back to the top
<!-- Vanilla JS -->
<script>
var timeOut;
function scrollToTop() {
if (document.body.scrollTop!==0 || document.documentElement.scrollTop!==0){
window.scrollBy(0,-50);
timeOut=setTimeout('scrollToTop()',10);
}
else clearTimeout(timeOut);
}
</script>
<a href="#top" onclick="scrollToTop();return false">Back to Top ↑</a>
<!-- jQuery -->
$(".scroll-up").on("click", function(e) {
e.preventDefault();
$("html, body").animate({ scrollTop: 0 }, 600);
});
<a href="#" class="scroll-up">Back to Top ↑</a>