Element.scrollIntoView() is an instance method from the CSSOM View module. It scrolls ancestor containers until this element is visible. Learn block / inline alignment, behavior: "smooth", the Promise interrupted flag, and five try-it labs.
01
Kind
Instance method
02
Action
Reveal element
03
block
start / center / end
04
Returns
Promise
05
behavior
smooth / instant
06
Status
Baseline widely
Fundamentals
Introduction
Long pages, tables of contents, and form validation often need to bring a specific element into view. Call element.scrollIntoView() and the browser scrolls every relevant ancestor until that element is visible.
MDN: you can pass a legacy boolean (true aligns top, false aligns bottom) or a modern options object with behavior, block, inline, and container. Modern browsers return a Promise with { interrupted }.
💡
Beginner tip
Use scrollIntoView() when you have a target element (anchor link, error field, last chat message). Use scroll() when you know exact pixel coordinates inside one scroll container.
Calling el.scrollIntoView(), el.scrollIntoView(true), or el.scrollIntoView({ block, inline, behavior, container }) scrolls scrollable ancestors so el appears in the viewport (MDN).
It is an instance method on Element (CSSOM View).
Scrolls ancestor containers (and optionally the viewport) until the element is visible.
Returns a Promise with { interrupted: boolean } (MDN).
block: start, center, end, nearest (default start).
inline: same values (default nearest).
Pair with CSS scroll-margin when sticky headers overlap targets (MDN).
MDN’s element methods demo scrolls the last paragraph into view inside an overflow section and uses the Promise to fade UI back in after smooth scrolling.
Applications
🚀 Common Use Cases
Table-of-contents links that jump to page sections.
Scrolling to the first invalid form field after validation fails.
Revealing the latest chat message or comment in a thread.
Animating to a card with behavior: "smooth" and block: "center".
Offsetting sticky headers with scroll-margin-top (MDN).
Syncing UI after scroll completes via the Promise interrupted flag.
🧠 How scrollIntoView() Reveals an Element
1
Pick the target element
Call scrollIntoView() on the element you want visible.
Target
2
Browser finds scrollable ancestors
Scrolls containers (and viewport) per container option (MDN).
Ancestors
3
Align with block / inline
Positions the element using block and inline alignment rules.
Align
4
✓
Promise resolves with interrupted
Element is visible; run follow-up UI when smooth scroll finishes (MDN).
Important
📝 Notes
Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available since January 2020).
scrollIntoView() scrolls ancestors until the element is visible (MDN).
Returns a Promise with { interrupted: boolean } (MDN).
Element.scrollIntoView() 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.scrollIntoView()
Safe for production. Scroll ancestors until an element is visible, 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
scrollIntoView()Excellent
Bottom line: Use scrollIntoView() to reveal a target element, scroll-margin for fixed headers, and await the Promise when smooth scrolling must finish before UI updates.
Wrap Up
Conclusion
Element.scrollIntoView() scrolls ancestor containers until the element is visible. It supports block / inline alignment, smooth animation, and returns a Promise you can await for polished scroll UX.
Use scrollIntoView() for anchor links and focus targets
Use block: "center" for TOC-style navigation
Add scroll-margin-top under fixed headers
Await the Promise to run UI after smooth scroll ends
Prefer the options object over the legacy boolean
❌ Don’t
Confuse scrollIntoView() with scroll()
Forget sticky navbars can cover the target
Assume IE returns a Promise
Fire many smooth scrolls without handling interrupted
Call on elements that are already fully visible unless you need alignment
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.scrollIntoView()
Reveal a target element—align with block/inline and optional smooth scroll.
5
Core concepts
📝01
Returns
Promise
API
📄02
Reveal
ancestors
Visible
✍️03
block
start/center
Align
✅04
Baseline
widely available
Status
⚡05
Pair
scroll-margin
Headers
❓ Frequently Asked Questions
It scrolls the element's ancestor containers so the element becomes visible to the user (MDN). You can pass a boolean or an options object.
No. MDN marks Element.scrollIntoView() as Baseline Widely available (since January 2020). It is not Deprecated, Experimental, or Non-standard.
A Promise that fulfills with { interrupted } — true if another programmatic scroll interrupted this one before it finished (MDN).
scrollIntoView() scrolls ancestors until this element is visible — you don't pick pixel coordinates. scroll() jumps to absolute offsets inside one scrollable element.
block controls vertical alignment (start, center, end, nearest). inline controls horizontal alignment (start, center, end, nearest). Defaults are start and nearest (MDN).
Use CSS scroll-margin-top or scroll-margin-bottom on the target element so scrollIntoView() leaves space for sticky/fixed navbars (MDN).
Did you know?
scrollIntoView() is what powers many in-page anchor links under the hood. Pair it with CSS scroll-margin when a sticky header would otherwise cover your target.