Favorites

DOM Window.scrollTo() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Window.scrollTo()
DOM Window MethodThis method is supported by all modern browsers.
Updated 28th November 2026

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, left and behavior ("smooth" or "auto").

Return Value

None (undefined).

Example

<div style="height:600px;background:linear-gradient(#e0e7ff,#fce7f3)">Long page</div>
<button id="top" type="button">Back to top</button>
document.getElementById('top').addEventListener('click', () => {
  window.scrollTo({ top: 0, behavior: 'smooth' });
});
window.scrollTo(0, 200);
console.log('scrollY:', window.scrollY);

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee