JavaScript Element scrollTo() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

Element.scrollTo() scrolls to a particular set of coordinates inside that element (MDN). Pass (x, y) or an options object with top, left, and behavior. MDN: this method is an alias for Element.scroll().

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call el.scrollTo. Start with this line.

JavaScript
el.scrollTo(x, y) or el.scrollTo(options)
CallWhat it does
el.scrollTo(x, y) or el.scrollTo(options)Primary signature.
el.scrollTo(...)Call with the arguments your case needs.

Built into the browser. Call scrollTo(...) on an Element — no import required.

Library declarations
JavaScript
el.scrollTo(x, y) or el.scrollTo(options)

Parameters

ParameterDescription
options.behaviorOptional. smooth, instant, or auto
Promise interruptedOptional. True if another scroll cut this one short

Return Value

Return ValueDescription
*Promise<{ interrupted }> (support varies)

JavaScript Examples

Example 1 — Scroll To Coordinates

MDN: scrollTo(0, 1000) — absolute position inside the element.

JavaScript
const box = document.getElementById("box");

box.scrollTo(0, 1000);
console.log("scrollTop:", box.scrollTop);
Try It Yourself

How It Works

  1. Absolute target. Left 0, top 1000.
  2. Not a delta. Calling again stays at the same place.
  3. Alias. Identical to box.scroll(0, 1000).
  4. Confirm. Read scrollTop (may clamp to max).

Example 2 — Smooth Options Object

MDN options form — often used for “back to top” with smooth motion.

JavaScript
const box = document.getElementById("box");

box.scrollTo({
  top: 0,
  left: 0,
  behavior: "smooth",
});
Try It Yourself

How It Works

  1. Object form. Clear when setting behavior.
  2. top: 0. Absolute top of the scrollport.
  3. smooth. Animates instead of jumping.
  4. Same as scroll(). Pick either name — same API.

Example 3 — Await the Promise

MDN: respond when a smooth scrollTo finishes; check interrupted.

JavaScript
const box = document.getElementById("box");

async function toTop() {
  const result = await box.scrollTo({
    top: 0,
    behavior: "smooth",
  });
  console.log("interrupted?", result.interrupted);
}

toTop();
Try It Yourself

How It Works

  1. Await finish. Useful after smooth “back to top”.
  2. interrupted. True if another programmatic scroll started first.
  3. Feature-detect. Test box.scrollTo(0, 0) instanceof Promise.
  4. Fallback. If no Promise, scroll still works — just no await.

Browser Support

Element.scrollTo() is Baseline Widely available (MDN, since January 2020). It is not Deprecated, Experimental, or Non-standard. Promise return / interrupted may vary — feature-detect if you depend on it.

✓ Baseline Widely available

Element.scrollTo()

Scroll an element to absolute coordinates. Alias of scroll(); pair with scrollBy for relative moves.

Baseline Widely available
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
scrollTo() Baseline

Bottom line: Safe for modern apps. Prefer options + behavior for smooth UX; detect Promise support before awaiting.

Frequently Asked Questions

It scrolls an element to a particular set of coordinates inside that element (MDN). Pass x/y numbers or an options object with top, left, and behavior.
No. MDN marks Element.scrollTo() as Baseline Widely available (since January 2020). It is not Deprecated, Experimental, or Non-standard. Some parts (such as the Promise return) may vary by browser.
MDN documents a Promise that fulfills with { interrupted }. interrupted is true if another programmatic scroll started on the same element before the first finished. Feature-detect if you rely on the Promise.
Yes. MDN documents scrollTo() as an alias for Element.scroll() — identical syntax and behavior.
scrollTo() jumps to absolute coordinates. scrollBy() adds a relative delta to the current position.
Optional string: smooth (animate), instant (jump), or auto (use the element’s CSS scroll-behavior). Default is auto (MDN).

Next: Element setAttribute()

Set or create an attribute on an element.

setAttribute() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful