The Window.scroll()
method scrolls the window to a particular place in the document.
Syntax
window.scroll(x-coord, y-coord) window.scroll(options)
Parameters
x-coord
is the pixel along the horizontal axis of the document that you want displayed in the upper left.y-coord
is the pixel along the vertical axis of the document that you want displayed in the upper left.
- or -
options
is aScrollToOptions
dictionary.
Examples
<!-- put the 100th vertical pixel at the top of the window --> <button onclick="scroll(0, 100);">click to scroll down 100 pixels</button>
Using options
:
window.scroll({
top: 100,
left: 100,
behavior: 'smooth'
});
Notes
Window.scrollTo()
is effectively the same as this method. For relative scrolling, see Window.scrollBy()
, Window.scrollByLines()
, and Window.scrollByPages()
.
For scrolling elements, see Element.scrollTop
and Element.scrollLeft
.
Specification
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View ModuleThe definition of 'window.scroll()' in that specification. | Working Draft | Initial definition. |
Browser Compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
scroll
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support 4 |
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
- No support
- No support
See also
Window.scroll() by Mozilla Contributors is licensed under CC-BY-SA 2.5.