Javascript | Window scrollTo() Method
The Window scrollTo() method is used to scroll to a particular set of coordinates in the document.
Syntax:
window.scrollTo(x-coord, y-coord)
Parameters: The scrollTo() method accepts two parameters as described below:
- x-coord: It is the pixel along the horizontal axis of the document that is displayed in the upper left. It is the required field.
- y-coord: It is the pixel along the vertical axis of the document that is displayed in the upper left. It is the required field.
Example:
<!DOCTYPE html> <html> <head> <title>Window scrollTo() Method</title> <style> body { width: 5000px; height: 5000px; margin-left: 260px; } </style> </head> <body> <h1 style="color:green;"> GeeksforGeeks </h1> <h2> Window scrollTo() Method </h2> <p> A computer science portal for geeks. </p> <button onclick="geek()">Click to scroll!</button> <script> function geek() { //Scrolling the document to position "250" //horizontally and "110" vertically window.scrollTo(250, 110); } </script> </body> </html> |
chevron_right
filter_none
Output:
Before clicking the button:

After clicking the button:

Supported Browsers: The browser supported by Window scrollTo() Method are listed below:
- Google Chrome
- Internet Explorer
- Firefox 1.0
- Opera
- Safari
Recommended Posts:
- Javascript | Window Open() & Window Close Method
- Javascript | Window Blur() and Window Focus() Method
- JavaScript | Window getComputedStyle() Method
- JavaScript | Window print() Method
- Javascript | Window confirm() Method
- Javascript | Window prompt() Method
- Window | Window.requestAnimationFrame() Method
- JavaScript | Window innerWidth and innerHeight Properties
- Cross-browser window resize event using JavaScript/jQuery
- How to check a webpage is loaded inside an iframe or into the browser window using JavaScript?
- How to set font size based on window size using JavaScript ?
- HTML | Window resizeTo() Method
- HTML | Window resizeBy() Method
- HTML | DOM Window stop() Method
- HTML | Window createPopup() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



