JavaScript Element scrollTo() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline
Instance method

What You’ll Learn

Element.scrollTo() is an instance method from the CSSOM View module. It scrolls an element to specific absolute coordinates inside that element. Learn the scroll() alias, behavior: "smooth", the Promise interrupted flag, and five try-it labs.

01

Kind

Instance method

02

Action

Scroll to coords

03

Alias

scroll()

04

Returns

Promise

05

behavior

smooth / instant

06

Status

Baseline widely

Introduction

Long pages, chat logs, and side panels often overflow their container. Instead of only setting element.scrollTop, you can call scrollTo() to jump to an absolute position—optionally with smooth animation.

MDN: scrollTo() is an alias of scroll(). Modern browsers return a Promise that resolves with { interrupted } so you can run code when a smooth scroll finishes (or was cut short by another scroll).

💡
Beginner tip

The element must be scrollable (overflow: auto or scroll). Use scrollTop to read the current position; use scrollTo() to set it programmatically.

This page is part of JavaScript Element. Related: scroll(), scrollTop, scrollHeight, and the JavaScript hub.

Understanding the scrollTo() Method

Calling el.scrollTo(x, y) or el.scrollTo({ top, left, behavior }) scrolls the element’s content so the given coordinates appear at the top-left of the visible scrollport.

  • It is an instance method on Element (CSSOM View).
  • Alias of scroll() with the same syntax (MDN).
  • Returns a Promise with { interrupted: boolean } (MDN).
  • Options: top, left, behavior (smooth, instant, auto).
  • Works on any element with overflow content (not only window).
  • Pair with scrollTop / scrollLeft to read position.

📝 Syntax

General forms of Element.scrollTo (MDN):

JavaScript
scrollTo(xCoord, yCoord)
scrollTo(options)

Parameters

  • xCoord, yCoord — pixels along X and Y to show at the upper-left of the element (MDN).
  • options (object):
    • top — Y-axis scroll position in pixels
    • left — X-axis scroll position in pixels
    • behavior"smooth", "instant", or "auto" (default)

Return value

A Promise that fulfills with { interrupted: boolean } (MDN).

Exceptions

  • No standard exceptions documented; invalid targets may simply not scroll.

Common patterns

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

panel.scrollTo(0, 1000);                    // MDN basic
panel.scrollTo({ top: 100, left: 0, behavior: "smooth" });

const result = await panel.scrollTo(0, 500);
console.log(result.interrupted);          // false if scroll finished

⚡ Quick Reference

GoalCode
Scroll to positionel.scrollTo(0, 1000)
Smooth scrollel.scrollTo({ top: 100, behavior: "smooth" })
Read positionel.scrollTop / el.scrollLeft
Scroll relativeel.scrollBy(0, 200)
Return valuePromise<{ interrupted }>
MDN statusBaseline Widely available (since January 2020)

🔍 At a Glance

Four facts to remember about Element.scrollTo().

Returns
Promise

{ interrupted }

Baseline
widely

Since Jan 2020

Alias
scroll

Same method

behavior
smooth

Optional animate

📋 scrollTo() vs scrollBy() vs scrollTop

scrollTo()scrollBy()scrollTop
Position typeAbsolute coordsRelative deltaProperty (read/write)
Aliasscroll()NoneN/A
behavior optionYesYesNo (instant)
Promise returnYes (MDN)Yes (MDN)No
Best forJump to sectionNudge by pixelsSimple read/set

Examples Gallery

Examples follow MDN Element.scrollTo() patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

MDN absolute coordinates and smooth scrolling.

Example 1 — Basic scrollTo(0, 1000) (MDN)

Put the 1000th vertical pixel at the top of a scrollable element.

JavaScript
const element = document.getElementById("section");

// MDN: scroll to y = 1000
element.scrollTo(0, 1000);
Try It Yourself

How It Works

MDN: the first argument is X, the second is Y. Both are absolute scroll offsets inside the element, not relative deltas.

Example 2 — Options With behavior: "smooth" (MDN)

Scroll with an options object for animated movement.

JavaScript
element.scrollTo({
  top: 100,
  left: 100,
  behavior: "smooth",
});
Try It Yourself

How It Works

behavior: "smooth" animates the scroll. You can also set CSS scroll-behavior: smooth and use behavior: "auto".

📈 Practical Patterns

scrollTop, Promise results, and overflow panels.

Example 3 — Scroll to Top scrollTo(0, 0) (MDN Demo)

MDN toolbar demo: jump a scrollable section back to the top.

JavaScript
document.querySelector(".scroll-to").addEventListener("click", async () => {
  const section = document.querySelector("section");
  const result = await section.scrollTo(0, 0);
  console.log("interrupted:", result.interrupted);
});
Try It Yourself

How It Works

MDN’s element methods demo uses scrollTo(0, 0) on a <section> with scroll-behavior: smooth in CSS.

Example 4 — Promise interrupted (MDN)

Detect when a smooth scroll was cut short by another scroll.

JavaScript
async function scrollAndReport(el, y) {
  const result = await el.scrollTo(0, y);
  console.log(result.interrupted ? "Interrupted" : "Finished");
}
Try It Yourself

How It Works

MDN: if you trigger a second scrollTo() before the first smooth scroll completes, the promise resolves with interrupted: true.

Example 5 — Overflow <section> (MDN Demo)

Scroll inside a fixed-height section with overflow-y: scroll.

JavaScript
const section = document.querySelector("section");

document.querySelector(".scroll").addEventListener("click", async () => {
  const result = await section.scrollTo(0, 1000);
  console.log("interrupted:", result.interrupted);
});
Try It Yourself

How It Works

MDN’s element methods demo uses a scrollable <section> with scroll-behavior: smooth in CSS for animated scrolling.

🚀 Common Use Cases

  • Scrolling a chat or comment thread to the latest message.
  • Jumping to a section inside a long sidebar or settings panel.
  • Animating to a position with behavior: "smooth".
  • Building “back to top” buttons for overflow containers.
  • Syncing UI after scroll completes via the Promise interrupted flag.
  • Teaching absolute vs relative scrolling (scroll vs scrollBy).

🧠 How scrollTo() Moves Content

1

Pick a scrollable element

The element needs overflow content (overflow: auto/scroll).

Target
2

Call scroll with coordinates

Pass (x, y) or { top, left, behavior } (MDN).

Request
3

Browser updates scroll offset

scrollTop / scrollLeft change to the new position.

Scroll
4

Promise resolves with interrupted

Run follow-up UI when smooth scrolling finishes (MDN).

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available since January 2020).
  • scrollTo() is an alias of scroll() (MDN).
  • Returns a Promise with { interrupted: boolean } (MDN).
  • Use scrollBy() for relative offsets; scrollTo() for absolute positions.
  • behavior: "smooth" animates; pair with CSS scroll-behavior when using auto.
  • Related: scrollTop, scrollHeight, scrollWidth, JavaScript hub.

Browser Support

Element.scrollTo() is Baseline Widely available (MDN: across browsers since January 2020). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Element.scrollTo()

Safe for production. Scroll an element to absolute coordinates with optional smooth behavior.

Baseline Widely available
Google Chrome Supported · Desktop & Mobile
Yes
Microsoft Edge Supported · Chromium
Yes
Mozilla Firefox Supported · Desktop & Mobile
Yes
Apple Safari Supported · macOS & iOS
Yes
Opera Supported · Modern versions
Yes
Internet Explorer Legacy scrollTop only · no Promise return
No
scrollTo() Excellent

Bottom line: Use scrollTo() for absolute positions, scrollBy() for relative nudges, and await the Promise when you need to know if a smooth scroll was interrupted.

Conclusion

Element.scrollTo() scrolls an element to absolute coordinates inside itself. It is the same as scroll(), supports smooth animation, and returns a Promise you can await when building polished scroll UX.

Continue with scroll(), scrollTop, scrollBy(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use scrollTo() for absolute jump-to positions
  • Use behavior: "smooth" for animated scrolling
  • Await the Promise to run UI after smooth scroll ends
  • Check scrollHeight before scrolling far down
  • Prefer options object syntax for clarity

❌ Don’t

  • Confuse scrollTo() with scrollBy()
  • Scroll elements without overflow content
  • Assume IE returns a Promise
  • Fire many smooth scrolls without handling interrupted
  • Forget that scrollTo() affects the element, not always window

Key Takeaways

Knowledge Unlocked

Five things to remember about Element.scrollTo()

Absolute scroll coordinates—optional smooth animation and Promise result.

5
Core concepts
📄 02

Alias

scrollTo

Same
✍️ 03

Coords

absolute

Position
04

Baseline

widely available

Status
05

Flag

interrupted

Promise

❓ Frequently Asked Questions

It scrolls an element to a particular set of coordinates inside that element (MDN). You can pass x/y numbers or an options object with top, left, and behavior.
No. MDN marks Element.scrollTo() as Baseline Widely available (across browsers since January 2020). It is not Deprecated, Experimental, or Non-standard.
A Promise that fulfills with an object containing interrupted — true if another programmatic scroll interrupted this one before it finished (MDN).
Yes. MDN documents scrollTo() and scroll() as aliases with identical syntax, parameters, and behavior.
scrollTo() jumps to absolute coordinates inside the element. scrollBy() adds a relative delta to the current scroll position.
Optional string: smooth (animated), instant (jump), or auto (uses CSS scroll-behavior). Default is auto (MDN).
Did you know?

element.scrollTo() and element.scroll() are the same method. Use scrollBy() when you want to move relative to the current position instead of jumping to absolute coordinates.

Next: scrollBy()

Continue the Element series with relative scrolling.

scrollBy() →

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.

8 people found this page helpful