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.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- 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
smoothanimates scrolling triggered by navigation or CSSOM scrolling APIs, such as following a fragment link.autoscrolls instantly.- It does not change direct user scrolling with a mouse wheel or touch gesture.
- The browser chooses the duration and easing for
smooth; CSSscroll-behaviorhas 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.
Rank #2
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.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteRank #3
- 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 onhtml. - 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.
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.
Quick Recap
Best Value
Rank #4
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.




