DOM Window.scrollTo() Method
The scrollTo() method scrolls the page to a given position, optionally with a smooth animation.
Description
The scrollTo() method scrolls the window to an exact position. With the options form, behavior: 'smooth' animates the scroll. scrollBy() scrolls relative to the current position, and elements have their own scrollTo() for scrollable containers. The current position is in window.scrollX and scrollY.
Smooth scrolling can also be set globally with the CSS scroll-behavior: smooth property, which then applies to anchor links too. Respect users who prefer reduced motion by using behavior: 'auto' when prefers-reduced-motion: reduce matches.
To scroll to a particular element rather than a pixel position, scrollIntoView() is usually easier, since it works out the position for you and handles scrollable containers as well as the page.
Syntax
scrollTo(x, y)
scrollTo({ top, left, behavior })Parameters
- x, yThe position to scroll to, in pixels.
- optionsAlternatively, an object with
top,leftandbehavior("smooth"or"auto").
Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the Window.scrollTo() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





