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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android ? Safari iOS Full support YesSamsung Internet Android Full support Yes
ScrollToOptions parameterChrome Full support 45Edge No support NoFirefox Full support YesIE No support NoOpera Full support 32Safari No support NoWebView Android Full support 45Chrome Android Full support 45Edge Mobile No support NoFirefox Android Full support YesOpera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

Document Tags and Contributors

Last updated by: mfluehr,