HTML DOM Element scrollIntoView
Example
Scroll the element with id="content" into the visible area of the browser window:
const element = document.getElementById("content");
element.scrollIntoView();
Try it Yourself »
More examples below.
Definition and Usage
The scrollIntoView()
method scrolls an element into the visible area of the browser window.
Syntax
element.scrollIntoView(align)
Parameters
Parameter | Description |
align | Optional. A boolean 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. |
Return Value
NONE |
More Examples
Example
Scroll to the top or to the bottom of an element:
const element = document.getElementById("content");
function scrollToTop()
{
element.scrollIntoView(true);
}
function scrollToBottom() {
element.scrollIntoView(false);
}
Try it Yourself »
Browser Support
element.scrollIntoView()
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |