Categories
JavaScript Answers

How to smooth scroll to top with JavaScript?

Spread the love

Sometimes, we want to smooth scroll to top with JavaScript.

In this article, we’ll look at how to smooth scroll to top with JavaScript.

How to smooth scroll to top with JavaScript?

To smooth scroll to top with JavaScript, we call the window.scrollTo method.

For instance, we write

window.scrollTo({ top: 0, behavior: "smooth" });

to call window.scrollTo with an object that specifies that we scroll to top position 0 and the scroll behavior is smooth to scroll to the top of the page with smooth scrolling.

Conclusion

To smooth scroll to top with JavaScript, we call the window.scrollTo method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.