Window scrollTo() method

Definition and usage

scrollTo() The method scrolls the document to the specified coordinates.

Tip:To make scrollTo() The method works when the document is larger than the screen, and the scrollbar must be visible.

See also:

scrollBy() method

instance

Example 1

Scroll the document to horizontal position 500:

window.scrollTo(500, 0);

try it yourself

Example 2

Scroll the document to vertical position 300:

window.scrollTo(0, 500);

try it yourself

Example 3

Scroll the document to horizontal position 300 and vertical position 500:

window.scrollTo(300, 500);

try it yourself

syntax

window.scrollTo(x, y)

or:

scrollTo(x, y)

parameters

parameters description
x Required. The coordinate (horizontal) to scroll to, in pixels.
y Required. The coordinate (vertical) to scroll to, in pixels.

Return Value

None.

Browser Support

All Browsers Support scrollTo():

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support