Element.scrollIntoView()

The Element interface's scrollIntoView() method scrolls the element's parent container such that the element on which scrollIntoView() is called is visible to the user

Syntax

element.scrollIntoView();
element.scrollIntoView(alignToTop); // Boolean parameter
element.scrollIntoView(scrollIntoViewOptions); // Object parameter

Parameters

alignToTop Optional
Is a Boolean value:
  • If true, the top of the element will be aligned to the top of the visible area of the scrollable ancestor. Corresponds to scrollIntoViewOptions: {block: "start", inline: "nearest"}. This is the default value.
  • If false, the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor. Corresponds to scrollIntoViewOptions: {block: "end", inline: "nearest"}.
scrollIntoViewOptions Optional
Is an Object with the following properties:
behavior Optional
Defines the transition animation.
One of auto or smooth. Defaults to auto.
block Optional
Defines vertical alignment.
One of start, center, end, or nearest. Defaults to start.
inline Optional
Defines horizontal alignment.
One of start, center, end, or nearest. Defaults to nearest.

Example

var element = document.getElementById("box");

element.scrollIntoView();
element.scrollIntoView(false);
element.scrollIntoView({block: "end"});
element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});

Notes

The element may not be scrolled completely to the top or bottom depending on the layout of other elements.

Specifications

Specification Status Comment
CSS Object Model (CSSOM) View Module
The definition of 'Element.scrollIntoView()' in that specification.
Working Draft Initial definition

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
scrollIntoView
Experimental
Chrome Full support 29Edge Full support 18
Notes
Full support 18
Notes
Notes The only parameter supported is alignToTop.
No support 12 — 18
Notes
Notes This function is implemented in the HTMLElement API, meaning non-HTML elements (like SVG elements) cannot use this function.
Notes No support for smooth behavior.
Firefox Full support 1IE Full support 8
Notes
Full support 8
Notes
Notes This function is implemented in the HTMLElement API, meaning non-HTML elements (like SVG elements) cannot use this function.
Notes No support for smooth behavior or center options.
Opera Full support 38Safari Full support 6
Notes
Full support 6
Notes
Notes No support for smooth behavior or center options.
WebView Android Full support ≤37Chrome Android Full support 29Firefox Android Full support 4Opera Android Full support 41Safari iOS Full support 5
Notes
Full support 5
Notes
Notes No support for smooth behavior or center options.
Samsung Internet Android Full support 2.0
scrollIntoViewOptions
Experimental
Chrome Full support 61
Notes
Full support 61
Notes
Notes The block and inline options support the values start, center, end, nearest.
Edge Full support 79
Notes
Full support 79
Notes
Notes The block and inline options support the values start, center, end, nearest.
Firefox Full support 36
Notes
Full support 36
Notes
Notes No support for inline option.
Notes Before Firefox 58, nearest and center values for the block option was unsupported. See bug 1389274.
IE No support NoOpera Full support 48
Notes
Full support 48
Notes
Notes The block and inline options support the values start, center, end, nearest.
Safari No support NoWebView Android Full support 61
Notes
Full support 61
Notes
Notes The block and inline options support the values start, center, end, nearest.
Chrome Android Full support 61
Notes
Full support 61
Notes
Notes The block and inline options support the values start, center, end, nearest.
Firefox Android Full support 36
Notes
Full support 36
Notes
Notes No support for inline option.
Notes Before Firefox 58, nearest and center values for the block option was unsupported. See bug 1389274.
Opera Android Full support 45
Notes
Full support 45
Notes
Notes The block and inline options support the values start, center, end, nearest.
Safari iOS No support NoSamsung Internet Android Full support 8.0
Notes
Full support 8.0
Notes
Notes The block and inline options support the values start, center, end, nearest.

Legend

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also