π What Is overscroll-behavior?
The overscroll-behavior property controls what happens when a user scrolls **past the boundary** of a scrollable container. It helps prevent unwanted browser behaviors such as:
- β The page scrolling when a nested element reaches its end
- β Pull-to-refresh on mobile
- β Scroll chaining between nested containers
- β Bounce/glow effects on some devices
Note
β Improves UX in modals, sidebars, carousels, and full-page apps
β Helps create app-like scrolling behavior
π¦ Syntax
overscroll-behavior syntax
overscroll-behavior: auto | contain | none;
/* Shorthand expands to */
overscroll-behavior-x: auto | contain | none;
overscroll-behavior-y: auto | contain | none;| Value | Description |
|---|---|
| auto | Default. Scroll chaining occurs normally. |
| contain | Prevents scroll chaining but allows default browser effects (e.g., bounce). |
| none | Prevents scroll chaining AND disables browser overscroll behaviors (e.g., pull-to-refresh). |
π 1. Prevent Scroll Chaining Inside a Modal
Modal scroll isolation
.modal-content {
overscroll-behavior: contain;
}When the modal reaches top/bottom scroll limit, the page behind it does not scroll. Useful for dialogs, sidebars, and drawers.
π 2. Disable Overscroll Completely
No overscroll at all
body {
overscroll-behavior: none;
}Prevents scroll chaining and browser overscroll actions like pull-to-refresh on mobile.
π 3. Prevent Horizontal Overscroll
Only lock X direction
.gallery {
overscroll-behavior-x: contain;
}Useful for horizontal carousels.
π 4. Prevent Vertical Overscroll (Scrollable Table)
Vertical containment
.table-wrapper {
overscroll-behavior-y: contain;
}π 5. Create an App-Like Fullscreen Scroll Experience
Web app smooth scrolling
html, body {
height: 100%;
overscroll-behavior: none;
}Prevents browser βbounceβ and system gestures from interfering.
π 6. Prevent Parent Scrolling When Reaching Child Scroll End
Nested scroll container
.scroll-box {
overflow: auto;
overscroll-behavior: contain;
}The scroll stays inside the element β the page never scrolls when you reach the end.
π§ͺ Real-World Examples
1οΈβ£ Chat App Message Pane
Chat scrolling
.chat-messages {
overscroll-behavior-y: contain;
}Prevents the entire page from scrolling when reaching the top/bottom of chat.
2οΈβ£ Mobile Navigation Drawer
Drawer scroll
.drawer {
overscroll-behavior: contain;
}3οΈβ£ iOS Pull-to-Refresh Disable (Common Use)
No pull-to-refresh
body {
overscroll-behavior: none;
}Prevents accidental pull-to-refresh interactions.
β οΈ Common Mistakes
- β Using overscroll-behavior on elements that do not scroll
- β Expecting it to stop scroll overflow β it only affects scroll behavior
- β Forgetting to set overflow: auto or scroll on scrollable containers
- β Overusing none, which disables useful system gestures
Note
π₯ Summary
The overscroll-behavior property allows you to control scroll boundaries, prevent scroll chaining, and block browser gestures like pull-to-refresh. It is essential for building modals, drawers, carousels, dashboards, and mobile web apps.
Learn more βMDN Docs π