English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM scrollIntoView() Method

HTML DOM Element Object

scrollIntoView()The method will scroll the element that calls it into the visible area of the browser window.

Note:Due to the layout of other elements, the element may not be able to scroll to the top or bottom completely.

Syntax:

element.scrollIntoView(alignToTop)
var elem = document.getElementById("box");
elem.scrollIntoView();
Test and See‹/›

Browser compatibility

The numbers in the table specify the first browser version that fully supports the scrollIntoView() method:

Method
scrollIntoView()283.5385.18

Parameter Values

ParametersDescription
alignToTop(Optional) A boolean value indicating the alignment type:

true-The top of the element will align with the top of the visible area of the scrollable ancestor

false-The bottom of the element will align with the bottom of the visible area of the scrollable ancestor.

If omitted, it will scroll to the top of the element.

Note:Some elements may not be able to scroll to the top or bottom completely due to the layout of other elements.

Technical Details

Return Value:None
DOM Version:CSS Object Model (CSSOM)

More Examples

Scroll to the top or bottom of an element:

var elem = document.getElementById("box");
function scrollToTop() {
   elem.scrollIntoView(true);
}
function scrollToBottom() {
   elem.scrollIntoView(false);
}
Test and See‹/›

HTML DOM Element Object