Scroll to the top of the page using JavaScript?

If you don’t need the change to animate then you don’t need to use any special plugins – I’d just use the native JavaScript window.scrollTo() method — passing in 0, 0 will scroll the page to the top left instantly.

window.scrollTo(xCoord, yCoord);


  • xCoord is the pixel along the horizontal axis.
  • yCoord is the pixel along the vertical axis.

Leave a Comment