CSS scroll-behavior Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Scrolling

What You’ll Learn

The scroll-behavior property controls whether scrolling is instant or animated. With one line of CSS you can make anchor links and in-page navigation feel smoother and more polished.

01

auto

Instant jump scroll.

02

smooth

Animated scroll.

03

html

Page-wide effect.

04

overflow

Container scroll.

05

anchors

#section links.

06

a11y

Reduced motion.

Introduction

The scroll-behavior property in CSS is used to control the scrolling behavior for a webpage.

This property specifies whether to use smooth scrolling or instant scrolling when a user navigates through internal links within a document or when a script calls for scrolling. Smooth scrolling provides a visually appealing and user-friendly experience, especially for single-page applications and websites with long content.

Definition and Usage

scroll-behavior applies to scroll containers — most commonly the root html element for the whole page, or any element with overflow: auto or overflow: scroll.

When set to smooth, clicking an anchor link such as <a href="#section"> scrolls gradually to the target instead of jumping instantly.

💡
Beginner Tip

Start with html { scroll-behavior: smooth; } on documentation pages and landing pages with section navigation.

📝 Syntax

The syntax for the scroll-behavior property is simple. It can be applied to the html element to affect the entire document, or to any scrollable container.

syntax.css
element {
  scroll-behavior: auto | smooth;
}

Basic Example

smooth-page.css
html {
  scroll-behavior: smooth;
}

Syntax Rules

  • Only two keyword values are valid: auto and smooth.
  • Apply to html for document-level scrolling.
  • Apply to a scroll container for scrolling inside that element.
  • Works with anchor links, focus moves, and many programmatic scroll APIs.
  • Does not expose custom duration or easing in pure CSS.

🎯 Default Value

The default value of the scroll-behavior property is auto, which provides an instant scrolling effect.

⚡ Quick Reference

QuestionAnswer
Default valueauto
Smooth page scrollhtml { scroll-behavior: smooth; }
Valid valuesauto, smooth
Applies toScroll containers
InheritedNo
AnimatableNo

💎 Property Values

ValueExampleDescription
autoscroll-behavior: auto;Instant scrolling with no animation. This is the default browser behavior.
smoothscroll-behavior: smooth;Animated scrolling that gradually moves to the target position.
auto smooth

When to Use scroll-behavior

scroll-behavior is the right tool when in-page navigation should feel gentler:

  • Anchor navigation — Smoothly scroll between sections linked with #id hashes.
  • Back-to-top links — Provide a softer return to the page header.
  • Scrollable panels — Improve UX inside sidebars, modals, or tab panels.
  • Documentation pages — Make long single-page layouts feel more polished.

Avoid overusing smooth scrolling where users need to jump quickly, and always respect prefers-reduced-motion.

👀 Live Preview

Click the section links below to see scroll-behavior: smooth inside this demo panel.

Section A
Section B
Section C

The scrollable box uses scroll-behavior: smooth.

Examples Gallery

Start with the reference smooth-scrolling page, compare instant auto behavior, smooth-scroll inside a container, and add a back-to-top link.

📜 Page-Level Scrolling

Enable smooth scrolling for anchor links across the document — matching the reference example.

Example 1 — Smooth anchor links

In this example, we’ll enable smooth scrolling for the entire webpage.

index.html
<style>
  html {
    scroll-behavior: smooth;
  }
  section {
    height: 100vh;
    padding: 20px;
  }
</style>

<nav>
  <a href="#section1">Section 1</a>
  <a href="#section2">Section 2</a>
</nav>
<section id="section1">Section 1</section>
<section id="section2">Section 2</section>
Try It Yourself

How It Works

Setting scroll-behavior: smooth on html affects all in-document scrolling triggered by anchor navigation.

Example 2 — Default auto scrolling

With scroll-behavior: auto, the browser jumps instantly to the target — useful as the default and for reduced-motion preferences.

auto-scroll.css
html {
  scroll-behavior: auto;
}
Try It Yourself

How It Works

auto is the initial value browsers use when you do not set scroll-behavior at all.

🗃 Container Scrolling

Smooth scrolling also works inside overflow boxes, not only on the full page.

Example 3 — Scrollable container

Apply scroll-behavior: smooth to the element that actually scrolls.

container-scroll.css
.panel {
  height: 220px;
  overflow-y: auto;
  scroll-behavior: smooth;
}
Try It Yourself

How It Works

The scrolling box must have a fixed height and overflow so anchor targets inside it can scroll.

Example 4 — Back to top link

A fixed “Back to top” button with href="#top" feels natural when page scrolling is smooth.

back-to-top.html
<style>
  html { scroll-behavior: smooth; }
</style>

<header id="top">...</header>
<a href="#top">Back to top</a>
Try It Yourself

How It Works

Pair smooth scrolling with a visible fixed action so long articles stay easy to navigate.

scroll-behavior with scroll-margin

Smooth scrolling looks best when the destination is fully visible. Fixed headers often cover linked sections. Use scroll-margin on targets so they stop below sticky navigation.

Also see overflow for creating scroll containers and position: sticky for persistent nav bars.

scroll-margin-top.css
section {
  scroll-margin-top: 4rem;
}

🧠 How scroll-behavior Works

1

User triggers a scroll

An anchor link, keyboard focus change, or script requests a new scroll position.

Trigger
2

Browser checks the container

The nearest scroll container’s scroll-behavior value is read.

auto | smooth
3

Scroll position updates

auto jumps instantly; smooth animates over a short browser-defined duration.

Motion
=

Polished navigation

In-page links feel intentional and easier to follow on long content.

Browser Compatibility

The scroll-behavior property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Edge, and Safari. Test anchor navigation on your target browsers and devices.

Scrolling · Modern support

Reliable smooth-scroll support

Current Chrome, Firefox, Safari, Edge, and Opera support scroll-behavior: smooth.

97% Modern browser support
Google Chrome 61+ · Desktop & Mobile
Full support
Mozilla Firefox 36+ · Desktop & Mobile
Full support
Apple Safari 15.4+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 48+ · Modern versions
Full support

Testing tip

Users with prefers-reduced-motion: reduce may prefer instant scrolling. Provide an auto fallback in a media query.

scroll-behavior property 97% supported

Bottom line: scroll-behavior: smooth is safe for modern projects; test sticky headers with scroll-margin.

Conclusion

The scroll-behavior property is a useful tool for enhancing user experience by providing smooth scrolling effects on your website.

By applying this property, you can make navigating long pages or single-page applications more visually appealing and user-friendly. Experiment with this property to see how it can improve the navigation and overall feel of your web projects.

💡 Best Practices

✅ Do

  • Set scroll-behavior: smooth on html for site-wide in-page navigation
  • Pair smooth scrolling with scroll-margin-top on section targets
  • Respect prefers-reduced-motion: reduce
  • Apply the property to the element that actually scrolls
  • Test anchor links with sticky headers and mobile browsers

❌ Don’t

  • Assume smooth scrolling replaces visible focus states
  • Rely on CSS alone for custom scroll timing or easing
  • Hide critical content behind long scroll animations
  • Forget container scrolling when links target elements inside overflow boxes
  • Force smooth scrolling for users who prefer reduced motion
reduced-motion.css
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

Key Takeaways

Knowledge Unlocked

Five things to remember about scroll-behavior

Use these points when building in-page navigation.

5
Core concepts
02

smooth

Animated scroll.

Pattern
03

html

Whole page.

Scope
04

overflow

Inner panels.

Container
🔄 05

reduced motion

Accessibility.

a11y

❓ Frequently Asked Questions

The scroll-behavior property controls whether scrolling happens instantly (auto) or with a smooth animated transition (smooth) when navigating via anchor links or programmatic scroll APIs.
Apply it to the html element for page-level smooth scrolling, or to any scrollable container with overflow: auto or overflow: scroll to smooth scrolling inside that box.
The default value is auto, which scrolls instantly without animation.
Yes. APIs like element.scrollIntoView({ behavior: 'smooth' }) and window.scrollTo({ top, behavior: 'smooth' }) work alongside CSS scroll-behavior on the scrolling container.
Yes. Many users prefer instant scrolling. Reset scroll-behavior to auto inside a prefers-reduced-motion: reduce media query.

Practice in the Live Editor

Open the HTML editor and try html { scroll-behavior: smooth; } with anchor links.

HTML Editor →

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.

5 people found this page helpful