Window.scrollTo()

Window.scrollTo() scrolls to a particular set of coordinates in the document.

Syntax

window.scrollTo(x-coord, y-coord)
window.scrollTo(options)

Parameters

  • x-coord is the pixel along the horizontal axis of the document that you want displayed in the upper left.
  • y-coord is the pixel along the vertical axis of the document that you want displayed in the upper left.

- or -

Examples

window.scrollTo(0, 1000);

Using options:

window.scrollTo({
  top: 100,
  left: 100,
  behavior: 'smooth'
});

Notes

Window.scroll() is effectively the same as this method. For relative scrolling, see Window.scrollBy(), Window.scrollByLines(), and Window.scrollByPages().

For scrolling elements, see Element.scrollTop and Element.scrollLeft.

Specifications

Specification Status Comment
CSS Object Model (CSSOM) View Module
The definition of 'window.scroll()' in that specification.
Working Draft Initial definition.

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollToChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0
ScrollToOptions parameterChrome Full support 45Edge Full support 79Firefox Full support YesIE No support NoOpera Full support 32Safari No support NoWebView Android Full support 45Chrome Android Full support 45Firefox Android Full support YesOpera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support 5.0

Legend

Full support
Full support
No support
No support