Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Scrolling, Interaction and UI

The scroll-behavior property

Reference for the CSS scroll-behavior property: turn on smooth scrolling for anchor links and script-driven scrolls, with a live demo, notes and motion tips.

The scroll-behavior property chooses how a scrolling box moves when something other than the user's own dragging or wheel input scrolls it. With smooth, the movement is animated over a short time; with auto, it jumps straight to the target.

It affects fragment navigation (clicking a link to #section), and scrolling started from JavaScript such as scrollTo() and scrollIntoView() when the script does not pass its own behavior option. It does not change how a mouse wheel, trackpad, keyboard or touch swipe scrolls.

CSS
html {
  scroll-behavior: smooth;
}

Try it

Smooth jumps inside a box

Switch smooth scrolling on, then press the jump buttons: the box glides instead of snapping.

Syntax

CSS
scroll-behavior: auto | smooth;
  • Initial value: auto
  • Applies to: scrolling boxes (and the viewport, when set on the root element)
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
auto Scroll positions change instantly.
smooth Scroll positions change with a browser-controlled animation. Duration and easing are chosen by the browser.

Usage notes

  • To smooth the page scroll, put the property on html (the root element). Setting it on body is not enough in most cases, because the viewport takes its value from the root.

  • The value on the scrolling box matters, not on the element you scroll to.

  • Long distances can feel slow or disorienting for some people. Respect the reduced-motion setting:

    CSS
    @media (prefers-reduced-motion: no-preference) {
      html { scroll-behavior: smooth; }
    }
    
  • A script can override the CSS: el.scrollIntoView({ behavior: "instant" }) skips the animation even when CSS says smooth.

  • Smooth scrolling interacts well with scroll-padding and scroll-margin, which keep targets from hiding under a sticky header.

  • Moving focus with a link or script can also trigger a smooth scroll, so keep the animation short in spirit: avoid huge pages with only a "back to top" link that takes many seconds.

Browser support

Supported in all current major browsers; it was added to some of them later than others, so very old versions simply scroll instantly, which is a safe fallback.