CSS scroll-behavior Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The scroll-behavior property sets how a scrolling box moves when scrolling is triggered by navigation (such as clicking an in-page link) or by certain CSSOM scroll APIs.

Use smooth for an animated jump, or auto for an instant jump. Set it on html for the viewport, or on a box with overflow: auto / scroll. It is not inherited. The initial value is auto.

Baseline · Widely available.

Not deprecated. User agents may ignore it. Wheel, touch, and scrollbar dragging are not affected — only navigational scrolls are.

CSS Syntax

syntax.css
scroll-behavior: auto | smooth;

Example: html { scroll-behavior: smooth; }

Property Values

ValueDescriptionTry it
autoInstant jump. Initial valueTry it
smoothAnimated scroll with a browser-defined easing and durationTry it
initialResets to autoTry it
inheritTakes the parent’s scroll-behaviorTry it

How to Use scroll-behavior

Pick the scrolling box, set smooth or auto, then respect reduced motion.

  1. For the whole page, set scroll-behavior on html (not only body).
  2. For an inner box, give it a fixed height and overflow: auto, then set scroll-behavior on that box.
  3. Add in-page links (href="#section") so navigation scrolling can be seen.
  4. Respect prefers-reduced-motion so smooth scrolling stays optional for motion-sensitive users.
PieceRequired?Role
Scrolling boxYeshtml, or a container with overflow that scrolls
auto or smoothYesInstant vs animated navigational scroll
Fragment / scroll targetUsuallyAnchor links show the effect clearly
Reduced-motion queryRecommendedKeep auto when the user prefers less motion

Live Preview

Click a link inside the box. Switch scroll-behavior between smooth and auto and compare the jump.

Use the in-box links. Dragging the scrollbar or using the wheel still feels the same either way.

Scroll box
Section A
Section B
Section C

scroll-behavior: smooth

CSS Examples

Each snippet focuses on scroll-behavior. Extra styles stay minimal for study. Use Try It Yourself for a live editor.

Example 1 — Smooth Scroll Container

Animate jumps inside an overflow box when you click section links.

CSS
<style>
  .box {
    height: 160px;
    overflow: auto;
    scroll-behavior: smooth;
  }
  .panel {
    height: 160px;
  }
</style>

<p>
  <a href="#a">A</a>
  <a href="#b">B</a>
</p>
<div class="box">
  <div id="a" class="panel">A</div>
  <div id="b" class="panel">B</div>
</div>
Try It Yourself

How It Works

  1. Make a scroll box. Fixed height plus overflow: auto creates a scrolling container.
  2. Set smooth. scroll-behavior: smooth animates navigational scrolls in that box.
  3. Link to ids. Clicking #a / #b triggers the scroll.
  4. Wheel still instant. Manual scrolling is unchanged.

Example 2 — Whole Page on html

Enable smooth scrolling for the viewport with the root element.

CSS
<style>
  html {
    scroll-behavior: smooth;
  }
  section {
    height: 100vh;
  }
</style>

<p>
  <a href="#one">One</a>
  <a href="#two">Two</a>
</p>
<section id="one">One</section>
<section id="two">Two</section>
Try It Yourself

How It Works

  1. Target the root. On html, the property applies to the viewport.
  2. Skip body-only. Setting it only on body does not propagate to the viewport.
  3. Use fragment links. In-page anchors trigger the smooth jump.
  4. Keep sections tall. Enough height makes the scroll obvious.

Example 3 — Respect Reduced Motion

Turn smooth scrolling off when the user prefers less motion.

CSS
<style>
  html {
    scroll-behavior: smooth;
  }
  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }
  }
</style>
Try It Yourself

How It Works

  1. Default to smooth. html { scroll-behavior: smooth; } for users with no preference.
  2. Query the preference. prefers-reduced-motion: reduce means less non-essential motion.
  3. Reset to auto. Instant jumps avoid vestibular triggers for those users.
  4. Same idea for boxes. Apply the media query to containers too, not only html.

Edge Cases & Pitfalls

If smooth scrolling seems broken, one of these is usually why.

user

Wheel and touch are unaffected

Manual scrolling never uses scroll-behavior. Test with fragment links, not the mouse wheel alone.

root

Use html, not only body

On the root element it applies to the viewport. A body-only rule does not propagate there.

a11y

Respect reduced motion

Animated page jumps can bother some users. Pair smooth with prefers-reduced-motion.

js

JS can override the style

scrollTo({ behavior: "smooth" }) / scrollIntoView({ behavior: "smooth" }) set behavior in the API call. CSS still helps when the default is used.

ua

Browsers may ignore it

The spec allows user agents to ignore scroll-behavior. Treat smooth scrolling as progressive enhancement.

Browser Support

scroll-behavior is a browser CSS property for scrolling boxes. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

scroll-behavior

Chrome 61+, Edge 79+, Firefox 36+, Safari 15.4+ / iOS 15.4+. Not supported in Internet Explorer.

97% Global support
Google Chrome 61+
Full support
Mozilla Firefox 36+
Full support
Apple Safari 15.4+
Full support
Microsoft Edge 79+
Full support
Opera 48+
Full support
Samsung Internet 8.2+
Full support
Internet Explorer No support
No support
scroll-behavior Widely supported

Bottom line: Safe for modern sites as progressive enhancement. Always offer instant scrolling when reduced motion is preferred. This is not a JavaScript runtime API.

Key Takeaways

  • Role: auto = instant jump; smooth = animated navigational scroll.
  • Where: set on html for the page, or on an overflow scroll container.
  • Not for wheel/touch. Only navigation (and some CSSOM) scrolls use it.
  • Accessibility: reset to auto under prefers-reduced-motion: reduce.

One line: scroll-behavior: smooth softens anchor jumps — never the mouse wheel.

Frequently Asked Questions

It controls whether navigational scrolls jump instantly (auto) or animate smoothly (smooth). It applies to scrolling boxes such as the viewport or an overflow: auto container.
No. User-driven scrolling (wheel, trackpad, touch, scrollbar drag) is not affected. Only navigation scrolls and certain CSSOM scrolls are.
Set it on the html (root) element. Specifying it on body alone does not apply it to the viewport.
The initial value is auto, which scrolls instantly with no animation.
Enable smooth scrolling only when the user has no reduced-motion preference, or reset scroll-behavior to auto inside @media (prefers-reduced-motion: reduce).
It is Baseline Widely available: Chrome 61+, Edge 79+, Firefox 36+, Safari 15.4+. It is a browser CSS property, not a Node.js feature. Internet Explorer does not support it.

Next: scroll-margin

Add space around scroll targets so sticky headers do not cover them.

scroll-margin tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful