Web/API/Window/scrollBy

From Get docs


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 ModuleThe definition of 'window.scrollBy()' in that specification. Working Draft Initial definition.

Browser Compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
scrollBy Chrome

Full support 1

Edge Full support 79


Full support 79


No support 12 — 79

Notes'

Notes' Only scrollBy(x-coord, y-coord) is supported.

Firefox

Full support 1

IE Partial support 11

Notes'

Partial support 11

Notes'

Notes' Only scrollBy(x-coord, y-coord) is supported.

Opera

Full support 3

Safari

Full support 1

WebView Android

Full support 1

Chrome Android

Full support 18

Firefox Android

Full support 4

Opera Android

Full support 10.1

Safari iOS

Full support 1

Samsung Internet Android

Full support 1.0

ScrollToOptions parameter Chrome

Full support 45

Edge

Full support 79

Firefox

Full support Yes

IE

No support No

Opera

Full support 32

Safari

No support No

WebView Android

Full support 45

Chrome Android

Full support 45

Firefox Android

Full support Yes

Opera Android

Full support 32

Safari iOS

No support No

Samsung 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.