W3cubDocs

/DOM

element.scrollIntoView

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The Element.scrollIntoView() method scrolls the element on which it's called into the visible area of the browser window.

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", "instant", or "smooth". Defaults to "auto".
block Optional
Defines vertical alignment.
One of "start", "center", "end", or "nearest". Defaults to "center".
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: "instant", 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

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 29 12
12
No support for smooth behavior.
1 8
8
No support for smooth behavior or center options.
38 5
5
No support for smooth behavior or center options.
scrollIntoViewOptions 61
61
The block and inline options support the values start, center, end, nearest.
? 36
36
No support for inline option.
Before Firefox 58, nearest and center values for the block option was unsupported. See bug 1389274.
No 48
48
The block and inline options support the values start, center, end, nearest.
No
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes ? 4 Yes 5
5
No support for smooth behavior or center options.
?
scrollIntoViewOptions 61
61
The block and inline options support the values start, center, end, nearest.
61
61
The block and inline options support the values start, center, end, nearest.
? 36
36
No support for inline option.
Before Firefox 58, nearest and center values for the block option was unsupported. See bug 1389274.
48
48
The block and inline options support the values start, center, end, nearest.
No ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/element/scrollIntoView