You are currently viewing Scroll to top in JavaScript

Scroll to top in JavaScript

Sharing is caring!

In this post, I’m going to show you how to create a scroll to top function in JavaScript. Scroll to top is a simple user-friendly feature. That lets the user return back to the top of the website with just one click.

HTML

<button onclick="scrollToTop()">Scroll To Top</button>

JavaScript

function scrollToTop(){
  window.scrollTo({
    top:0,
    behavior:'smooth'
  })
}

Keywords: javascript scroll to top, scroll to top javascript, scroll to top js.

Sharing is caring!

This Post Has One Comment

Leave a Reply