English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Window scrollBy() method

JavaScript Window Object

scrollBy()the method scrolls the document in the window by a specified number of pixels.

scrollBy() scrolls the document by a specified number of pixels, whilewindow.scrollTo()Scroll to the absolute position in the document.

Syntax:

window.scrollBy(x-coord, y-coord)
<button onclick="window.scrollBy(0,10">Click</button>
Test See </›

Browser compatibility

All browsers fully support the scrollBy() method:

Method
scrollBy()YesYesYesYesYes

Parameter Value

ParameterDescription
x-coordThe horizontal pixel value you want to scroll. Positive values will scroll right, and negative values will scroll left.
y-coordThe vertical pixel value you want to scroll. Positive values will scroll down, and negative values will scroll up.

Technical Details

Return Value:None

More Examples

Vertical Scroll Document100 pixels:

<button onclick="window.scrollBy(0, 100);">Click</button>
Test See </›

Horizontal and Vertical Scroll Document:

<button onclick="window.scrollBy(0, 50)">Scroll Down</button>
<button onclick="window.scrollBy(0, -50)">Scroll Up</button>
<button onclick="window.scrollBy(0,100, 0)">Scroll Right</button>
<button onclick="window.scrollBy(0,-100, 0)">Scroll Left</button>
Test See </›

Related References

Window (Window) Reference:window.scrollTo() method

HTML DOM Reference:element.scrollLeft property

HTML DOM Reference:element.scrollTop property

JavaScript Window Object