scroll-behavior

Enables smooth scrolling when jumping to anchors and when scrolling via script.

Initial value
auto
Inherited
No
Animatable
no
Applies to
scroll containers
JavaScript
element.style.scrollBehavior = "smooth"
On this page

Example

#
CSS
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
Preview

Definition and usage

#

The scroll-behavior: smooth property makes jumps to places on the page, for example after clicking a #section link, happen with a smooth animation instead of an instant jump.

It applies to scrolling triggered by navigation and by JavaScript, for example element.scrollIntoView(). It doesn’t change scrolling with the mouse wheel or a finger.

It is usually set on the html element. For people with the reduced-motion setting, it is worth turning smooth scrolling off in a prefers-reduced-motion query.

Syntax

#
Syntax
scroll-behavior: auto | smooth;

Values

#
  • auto

    An instant jump after clicking the link.
  • smooth

    Smooth scrolling to the target.

Values in practice

#

auto

An instant jump after clicking the link.
.demo { scroll-behavior: auto; }

smooth

Smooth scrolling to the target.
.demo { scroll-behavior: smooth; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • With a sticky header, add scroll-margin-top to the targets so the header doesn’t cover them.
  • Turn smooth scrolling off for prefers-reduced-motion: reduce.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.