How to scroll to the bottom of the webpage using JavaScript?

Published February 5, 2021

To scroll to the bottom of the webpage using JavaScript, first, we need to get the full scrollable height of the window. The scrollable height is the total pixels away from the top of the webpage.

We can get that using the scrollHeight property in the document.body global object like this,

// get the scroll height of the window
const scrollHeight = document.body.scrollHeight;

Now, all we need to do is to use the scrollTo() method in the global window object and pass 0 as the first argument and the scrollHeight as the second argument to it like this,

// get the scroll height of the window
const scrollHeight = document.body.scrollHeight;

// scroll to the bottom of webpage
window.scrollTo(0, scrollHeight);

That's it 🌟!

See this example live in JSBin.

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter