Favorites

DOM Element.scrollIntoView() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Element.scrollIntoView()
DOM Element MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The scrollIntoView() method scrolls the page, and any scrollable containers, so that an element becomes visible.

Description

The scrollIntoView() method scrolls the element's ancestor containers so that the element is visible. Options control whether the scroll is smooth and where the element ends up: at the start, centre, end, or the nearest edge. The CSS scroll-margin-top property adds space above it, which is useful under a fixed header.

It scrolls every scrollable ancestor as needed, not just the window. Calling it with true or false is an older form that aligns the top or bottom of the element. Smooth scrolling respects the user's reduced-motion preference in some browsers, but checking prefers-reduced-motion yourself and using 'auto' when it's set is kinder to users who find motion uncomfortable.

It doesn't move keyboard focus; if you're scrolling to an element the user should interact with, call focus() on it as well, which also scrolls it into view.

Syntax

element.scrollIntoView()
element.scrollIntoView({ behavior, block, inline })

Parameters

  • optionsOptional. behavior ("auto" or "smooth"), and block and inline ("start", "center", "end" or "nearest").

Return Value

None (undefined).

Example

<button id="go" type="button">Scroll to target</button>
<div style="height:400px"></div>
<p id="target" style="background:#fde68a">Target</p>
<div style="height:400px"></div>
document.getElementById('go').addEventListener('click', () => {
  document.getElementById('target').scrollIntoView({ behavior: 'smooth', block: 'center' });
  console.log('Scrolled to target');
});

Browser Support

The following information will show you the current browser support for the Element.scrollIntoView() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee