Published on

Scroll to Specific Element with JavaScript

Authors

Scrolling to specific element is a common feature and it allowing users to navigate easily. You may have noticed the “Scroll to Top” icon in the bottom left corner on the blog.

Let's see how to implement that with just JavaScript without using Browser API - scrollToView

// select the element that you want to scroll into
const el = document.querySelector('footer')

// Now scroll to it with scrollIntoView method
el.scrollIntoView({behavior: "smooth"}) 

That's it.

It'll take care of scrolling up or down, depending on the element and smoothly scroll into it.

Happy smooth scrolling!