Window scrollTo()
Example
Scroll the document to the horizontal position 500:
window.scrollTo(500, 0);
Try it Yourself »
Scroll the document to the vertical position 500:
window.scrollTo(0, 500);
Try it Yourself »
More examples below.
Description
The scrollTo()
method scrolls the document to specified coordinates.
Note
For the scrollTo()
method to work,
the document must be larger than the screen, and the scrollbar must be visible.
See Also:
Syntax
window.scrollTo(x, y)
or just:
scrollTo(x, y)
Parameters
Parameter | Description |
x | Required. The coordinate to scroll to (horizontally), in pixels. |
y | Required. The coordinate to scroll to (vertically), in pixels. |
Return Value
NONE |
More Examples
Scroll the document to position 300 horizontally and 500 vertically:
window.scrollTo(300, 500);
Try it Yourself »
Browser Support
scrollTo()
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |