THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Window scrollTo() Method

Window Object Reference Window Object

Example

Scroll the document to the horizontal position "500":

window.scrollTo(500, 0);
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

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

Tip: Use the scrollBy() method to scroll a specified distance multiple times.


Browser Support

Method
scrollTo() Yes Yes Yes Yes Yes

Syntax

window.scrollTo(xpos,ypos)

Parameter Values

Parameter Type Description
xpos Number Required. The coordinate to scroll to, along the x-axis (horizontal), in pixels
ypos Number Required. The coordinate to scroll to, along the y-axis (vertical), in pixels

Technical Details

Return Value: No return value

Examples

More Examples

Example

Scroll the document to position "300" horizontally and "500" vertically:

window.scrollTo(300, 500);
Try it Yourself »

Related Pages

Window Object: scrollBy() Method


Window Object Reference Window Object