HTML Window scrollBy() method (original) (raw)
Last Updated : 15 Jun, 2023
The window.scrollBy() method is used to scroll the document by a given number of pixels.
Syntax:
window.scrollBy( xcoordinate, ycoordinate );
or
window.scrollBy(options);
Parameters: This method accepts two parameters as mentioned above and described below:
- x-coordinate: It is the horizontal pixel value that indicates how much you want to scroll the document (in terms of px).
- y-coordinate: It is the vertical pixel value that indicates how much you want to scroll the document (in terms of px).
Note: You can find these options in options in the ScrollToOptions dictionary.
Example 1: Scroll horizontally
HTML `
HTML DOM window scrollby() methodGeeksforGeeks
HTML DOM Window.scrollBy() method
Scroll horizontally!<script>
function scrollby() {
window.scrollBy(100, 0);
}
</script>
`
Output:

Example 2: Using options
HTML `
HTML DOM Window scrollBy() methodGeeksForGeeks
HTML DOM Window.scrollBy() method
Scroll down
Scroll up
Scroll right
Scroll left
Scroll up
Scroll right
Scroll left
<script>
function scrollWin(x, y) {
window.scrollBy(x, y);
}
</script>
`
Output:

Supported Browsers: The browser supported by HTML DOM Window scrollBy() method are listed below:
- Google Chrome 45
- Firefox
- Opera 32