# Method for scrolling a window by the amount in JavaScript

The `scrollBy` method scrolls the window by the given amount from the current position. It takes the horizontal shift as the first parameter, and the vertical shift as the second. Let's scroll the window by the given amounts:

`window.scrollBy(100, 200);`

Let's scroll backwards:

`window.scrollBy(-100, -200);`

Here we perform smooth scrolling:

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

On button click, scroll the window down by `100px`.

On button click, scroll the window up by `100px`.

On button click, smoothly scroll the window down by `300px`.

On button click, smoothly scroll the window up by `300px`.

← →
↑
en ru