THE WORLD'S LARGEST WEB DEVELOPER SITE

HTML DOM scrollIntoView Method

❮ Element Object

Example

Scroll the element with id="content" into the visible area of the browser window:

var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The scrollIntoView() method scrolls the specified element into the visible area of the browser window.


Browser Support

The numbers in the table specifies the first browser version that fully supports the method.

Method
scrollIntoView 28.0 8.0 1.7 5.0 38.0

Syntax

element.scrollIntoView(alignTo)

Parameters

Parameter Type Description
alignTo Boolean Optional. A boolean value that indicates the type of the align:

true - the top of the element will be aligned to the top of the visible area of the scrollable ancestor

false - the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor.

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

Note: Depending on the layout of other elements, some elements may not be scrolled completely to the top or to the bottom.


Technical Details

Return Value: No return value
DOM Version Experimental

More Examples

Example

Scroll to the top or to the bottom of an element:

var elmnt = document.getElementById("content");

function scrollToTop() {
    elmnt.scrollIntoView(true); // Top
}

function scrollToBottom() {
    elmnt.scrollIntoView(false); // Bottom
}
Try it Yourself »

❮ Element Object