Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save macminimaru/271eb78b5da0e50d6036b2ce77ad40f6 to your computer and use it in GitHub Desktop.

Select an option

Save macminimaru/271eb78b5da0e50d6036b2ce77ad40f6 to your computer and use it in GitHub Desktop.
The One-Line UX Fix Nobody Remembers: overscroll-behavior: contain
# The One-Line UX Fix Nobody Remembers: `overscroll-behavior: contain`
## The Core Idea
Scroll chaining — when you scroll inside a modal, dropdown, or sidebar and suddenly the page behind it starts scrolling too — is one of the web's most persistent micro-frictions. And it's fixable with exactly one line of CSS:
```css
.modal__content {
overscroll-behavior: contain;
}
```
But behind this single property is a surprisingly deep picture of how browsers handle scroll propagation — and what it reveals about the gap between what designers intend and what browsers default to.
## Three Sources Converging on the Same Problem
### 1. The Property Itself
`overscroll-behavior` landed in Chrome 63 (2017) and has since gained universal browser support. It controls what happens when a scroll container reaches its boundary:
- `auto` — the default: scroll chains to the parent
- `contain` — stops the scroll at the boundary; no chaining
- `none` — also disables overscroll affordances (pull-to-refresh, rubberbanding, glow effects)
The Chrome Developers blog post by Eric Bidelman and Majid Valipour walks through the original motivation: mobile app drawers, chat panels, and page overlays all suffered from scroll chaining, and there was no CSS way to fix it without JavaScript hackery.
### 2. The Nested Scroll Paradox
The deeper ux problem is that **modern interfaces are Russian dolls of scrollable containers**: modals inside pages, code snippets inside documentation panels, carousels inside sidebars. Each nested scroll container is a potential failure point where user intent (scroll THIS) and browser behavior (scroll EVERYTHING) diverge.
The problem is compounded by:
- **Content-dependent**: scroll chaining only manifests when the inner container is full. A modal with 3 items works perfectly; the same modal with 30 items is suddenly broken. This makes it extremely hard to catch in design review.
- **Device-specific**: trackpad and touch gestures are more prone to chaining than mouse wheel scroll. A QA test on a desktop might pass; the same interaction on a phone or laptop trackpad fails.
- **Framework-agnostic**: React, Vue, Svelte — none of them help here. It's a browser behavior, not a framework one.
### 3. Design System Hygiene
For teams building design systems, scroll chaining is a telling failure mode. Your modal component is tested in isolation with canned content. In production, product teams stuff it with arbitrarily long content. The scroll chain appears. The design system is blamed. But the fix (`overscroll-behavior: contain`) was never in the component spec.
**The lesson: every scrollable container in a design system should default to `overscroll-behavior: contain` unless there's an explicit reason to chain.** It's not optional polish — it's structural hygiene, like `box-sizing: border-box`.
## The Connecting Thread
This is a case study in **defaults-as-design**. The browser defaults to scroll chaining because it's the safe, historically compatible choice. But the safe default is often the wrong one for real interfaces. The gap between "technically correct" and "actually pleasant to use" is where this one line of CSS lives.
For anyone building components that end users interact with — and especially for design system maintainers — `overscroll-behavior: contain` is the kind of fix that nobody notices when it's there and everybody notices when it's not. It lives in the same category as `outline: none` with a proper focus style: invisible when done right, glaring when missing.
---
*Crossposted from a link Ajmal shared in foxhound: twitter.com/ankur5ahu/status/2076286920477552923*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment