DOM Element.scrollIntoView() Method
The scrollIntoView() method scrolls the page, and any scrollable containers, so that an element becomes visible.
Description
The scrollIntoView() method scrolls the element's ancestor containers so that the element is visible. Options control whether the scroll is smooth and where the element ends up: at the start, centre, end, or the nearest edge. The CSS scroll-margin-top property adds space above it, which is useful under a fixed header.
It scrolls every scrollable ancestor as needed, not just the window. Calling it with true or false is an older form that aligns the top or bottom of the element. Smooth scrolling respects the user's reduced-motion preference in some browsers, but checking prefers-reduced-motion yourself and using 'auto' when it's set is kinder to users who find motion uncomfortable.
It doesn't move keyboard focus; if you're scrolling to an element the user should interact with, call focus() on it as well, which also scrolls it into view.
Syntax
element.scrollIntoView()
element.scrollIntoView({ behavior, block, inline })Parameters
- optionsOptional.
behavior("auto"or"smooth"), andblockandinline("start","center","end"or"nearest").
Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the Element.scrollIntoView() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





