Element.scrollBy() is an instance method from the CSSOM View module. It scrolls an element by a given amount relative to where it is now. Learn delta scrolling, behavior: "smooth", the Promise interrupted flag, and five try-it labs.
01
Kind
Instance method
02
Action
Scroll by delta
03
Vs scroll()
Relative not absolute
04
Returns
Promise
05
behavior
smooth / instant
06
Status
Baseline widely
Fundamentals
Introduction
Carousels, image galleries, and long panels often need a small nudge—not a jump to pixel 1000. Call scrollBy() to move relative to the current scroll position by a number of pixels.
MDN: scrollBy(x, y) adds to the current offset. Like scroll(), modern browsers return a Promise with { interrupted } so you can run code when a smooth scroll finishes (or was cut short).
💡
Beginner tip
Think of scroll() as “go to this spot” and scrollBy() as “move this many pixels from here.” Use negative values to scroll up or left.
scrollTop and scrollLeft increase by 300 (if content allows).
How It Works
MDN: the first argument is horizontal delta, the second is vertical delta. Values are added to the current scroll position, not set as absolute coordinates.
Example 2 — Options With behavior: "smooth" (MDN)
Scroll relatively with an options object for animated movement.
Element.scrollBy() 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.scrollBy()
Safe for production. Scroll an element by a relative delta with optional smooth behavior.
BaselineWidely available
Google ChromeSupported · Desktop & Mobile
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop & Mobile
Yes
Apple SafariSupported · macOS & iOS
Yes
OperaSupported · Modern versions
Yes
Internet ExplorerLegacy scrollTop only · no Promise return
No
scrollBy()Excellent
Bottom line: Use scrollBy() for relative nudges, scroll() for absolute jumps, and await the Promise when you need to know if a smooth scroll was interrupted.
Wrap Up
Conclusion
Element.scrollBy() scrolls an element by a relative amount from its current position. It supports smooth animation, works on any overflow container, and returns a Promise you can await when building polished scroll UX.
Await the Promise to run UI after smooth scroll ends
Use negative deltas to scroll up or left
Prefer options object syntax for clarity
❌ Don’t
Confuse scrollBy() with scroll()
Scroll elements without overflow content
Assume IE returns a Promise
Fire many smooth scrolls without handling interrupted
Use absolute coordinates when a delta is simpler
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.scrollBy()
Relative scroll deltas—optional smooth animation and Promise result.
5
Core concepts
📝01
Returns
Promise
API
📄02
Delta
relative
Offset
✍️03
Flag
interrupted
Promise
✅04
Baseline
widely available
Status
⚡05
Pair
scroll()
Absolute
❓ Frequently Asked Questions
It scrolls an element by the given amount relative to its current position (MDN). Pass x/y deltas or an options object with top, left, and behavior.
No. MDN marks Element.scrollBy() 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).
scrollBy() adds a delta to the current scroll position. scroll() (alias of scrollTo()) jumps to absolute coordinates inside the element.
Optional string: smooth (animated), instant (jump), or auto (uses CSS scroll-behavior). Default is auto (MDN).
Yes. Pass a positive or negative left/x value, e.g. scrollBy(200, 0) or scrollBy({ left: 200, behavior: "smooth" }).
Did you know?
element.scrollBy() adds pixels to the current scroll position. Use scroll() when you need to jump to an absolute coordinate instead.