Window.scrollTo()
scrolls to a particular set of coordinates in the document.
Syntax
window.scrollTo(x-coord, y-coord) window.scrollTo(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
window.scrollTo(0, 1000);
Using options
:
window.scrollTo({
top: 100,
left: 100,
behavior: 'smooth'
});
Notes
Window.scroll()
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
.
Specifications
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
scrollTo
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support 4 |
Opera
Full support 4 |
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
Window.scrollTo() by Mozilla Contributors is licensed under CC-BY-SA 2.5.