Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

How to Create Smooth Scrolling with CSS

Use scroll-behavior: smooth on the root element or the actual scroll container, with a reduced-motion override for visitors who prefer less motion.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set scroll-behavior: smooth on the root html element to make in-page links scroll smoothly. For a scrollable panel, apply it to that panel instead. Add a prefers-reduced-motion override so visitors who request less motion get instant scrolling.

Make anchor links scroll smoothly

Use ordinary fragment links and give the destination a matching ID. The browser handles navigation; CSS changes how the scrolling moves.

<nav aria-label="Page contents">
  <a href="#details">Go to details</a>
</nav>

<section id="details">
  <h2>Details</h2>
  <p>The linked section appears here.</p>
</section>

<style>
  html {
    scroll-behavior: smooth;
  }

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

The html rule sets scrolling behavior for the document viewport. Do not rely on setting the property on body: it does not propagate to the viewport. See MDN’s scroll-behavior reference.

Apply smooth scrolling to a nested container

If a region scrolls independently—such as a panel with a fixed height—set the property on that scrolling box, not on the page root.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
.scroll-container {
  max-height: 20rem;
  overflow-y: auto;
  scroll-behavior: smooth;
}

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

Links or script-driven scrolling within that container can then move smoothly. A root rule and a container rule serve different scrolling boxes; apply the declaration to the one that actually scrolls.

What the property changes—and what it does not

  • smooth animates scrolling triggered by navigation or CSSOM scrolling APIs, such as following a fragment link.
  • auto scrolls instantly.
  • It does not change direct user scrolling with a mouse wheel or touch gesture.
  • The browser chooses the duration and easing for smooth; CSS scroll-behavior has no setting for a fixed speed or timing curve. The W3C CSSOM View specification leaves the timing to the user agent and allows a smooth scroll to be interrupted by the user or an algorithm.

The property is not animatable, and browsers are permitted to ignore it. MDN marks it Baseline Widely available, with availability across browsers since March 2022; check its live compatibility table if your project has strict minimum-version requirements.

Respect reduced-motion preferences

The prefers-reduced-motion: reduce media query matches when a visitor has enabled an operating-system or device setting to minimize non-essential motion. Setting scroll-behavior: auto inside that query makes the relevant scrolling immediate. Keep the override after the general smooth-scroll rule so it wins in the cascade.

This is a small accommodation for people who may experience discomfort from motion. For background on the preference, see MDN’s prefers-reduced-motion reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Troubleshoot smooth scrolling that does not work

  • Anchor link jumps instantly: confirm the rule is on html, the destination ID matches the link fragment, and no later CSS rule overrides it. If the visitor has reduced motion enabled, the instant movement is expected.
  • A panel scrolls instantly but the page does not: set the property on the element with overflow-y: auto (or other scrolling overflow), not just on html.
  • Wheel or touch movement is unchanged: that is expected; this property affects navigation- or API-triggered scrolling, not direct input.
  • It works in some browsers but not others: browser support is broad, but user agents may ignore the property. Check the current MDN compatibility data for the browsers and versions you support.
  • You want a precise duration or easing: this CSS property does not expose those controls; the browser defines both for smooth scrolling.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is to capture a page rather than build its scrolling behavior, ScreenshotNeo can return a website screenshot or PDF through a single GET request. It is a screenshot API and MCP server, not a replacement for the CSS implementation above. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month, with no card required.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.