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

// 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 where window.scroll scrolls to an absolute position in the document. See also window.scrollByLines, 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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support YesEdge Partial support Partial
Notes
Partial support Partial
Notes
Notes Only scrollBy(x-coord, y-coord) is supported.
Firefox Full support YesIE Partial support 11
Notes
Partial support 11
Notes
Notes Only scrollBy(x-coord, y-coord) is supported.
Opera ? Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android ? Safari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Partial support  
Partial support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

Document Tags and Contributors

Last updated by: chrisdavidmills,