CSS Reference ยท Scrolling, Interaction and UI
The overscroll-behavior property
Reference for the CSS overscroll-behavior property: stop scroll chaining from inner panels to the page and disable bounce effects, with a live example.
When you scroll an inner box to its end and keep scrolling, the browser normally passes the remaining movement to the next scrollable ancestor, usually the page. This is called scroll chaining. The overscroll-behavior property controls what happens at the edge of a scroll container: let the scroll chain on, stop it, or also remove the browser's bounce or pull-to-refresh effects.
It is common for modals, dropdown menus, chat panels and sidebars, where scrolling the page behind them would feel wrong.
.modal-body { overflow-y: auto; overscroll-behavior: contain; }
Try it
Syntax
overscroll-behavior: [ contain | none | auto ]{1,2}; overscroll-behavior-x: contain | none | auto; overscroll-behavior-y: contain | none | auto; overscroll-behavior-inline | overscroll-behavior-block: contain | none | auto;
- Initial value:
auto - Applies to: scroll containers
- Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
Default. Scrolling chains to ancestors and default overscroll effects happen. |
contain |
No chaining to the ancestors, but the box's own overscroll effect (such as a glow or bounce) can still show. |
none |
No chaining and no overscroll effect. |
| Two values | First is for the horizontal axis, second for the vertical. |
Usage notes
- It only matters when the box actually scrolls. If the content fits, the box is not a scroll container and there is nothing to contain.
containis the usual choice for panels inside the page. It does not block the user from scrolling the page by scrolling outside the panel.- Setting
overscroll-behavior-x: noneonhtmlcan block swipe-back navigation on some devices. Think carefully before removing a gesture people use. - Setting
overscroll-behavior-y: containonbodycan disable pull-to-refresh in mobile browsers that support it, which is useful for web apps with their own refresh gesture. - Compared with
overflow: hiddenon the body for modals,containkeeps the page scrollbar and does not cause layout shift.
Browser support
Supported in current Chromium and Firefox browsers, and in recent Safari releases; older versions ignore it and chain as normal, so check a compatibility table when supporting them.
Related
overflowโ creates scroll containerstouch-actionโ controls touch gesturesscroll-snap-typeโ snapping- Lesson: Scroll Snap