Window.scrollBy()

The Window.scrollBy() method scrolls the document in the window by the given amount.

Syntax

window.scrollBy(x-coord, y-coord);
window.scrollBy(options)

Parameters

  • x-coord is the horizontal pixel value that you want to scroll by.
  • y-coord is the vertical pixel value that you want to scroll by.

- or -

Examples

To scroll down one page:

window.scrollBy(0, window.innerHeight);

To scroll up:

window.scrollBy(0, -window.innerHeight);

Using options:

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

Notes

window.scrollBy() scrolls by a particular amount, whereas window.scroll() scrolls to an absolute position in the document. See also window.scrollByLines() and window.scrollByPages().

Specification

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

Browser Compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollByChrome Full support 1Edge Full support 79
Full support 79
No support 12 — 79
Notes
Notes Only scrollBy(x-coord, y-coord) is supported.
Firefox Full support 1IE Partial support 11
Notes
Partial support 11
Notes
Notes Only scrollBy(x-coord, y-coord) is supported.
Opera Full support 3Safari 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
Partial support
Partial support
No support
No support
See implementation notes.
See implementation notes.