CSS propertyInteraction and more
overscroll-behavior
Prevents the whole page from scrolling after reaching the end of a scrollable element.
- Initial value
auto- Inherited
- No
- Animatable
- no
- Applies to
- scroll containers
- JavaScript
element.style.overscrollBehavior = "contain"
Example
#CSS
.chat-messages {
max-height: 320px;
overflow-y: auto;
overscroll-behavior: contain;
}Example HTML
<p style="margin: 0; color: #a3a3a3;">The chat window scrolls independently of the page, even when you reach the oldest message.</p>Preview
Definition and usage
#When you scroll a list inside a page and reach its end, further scrolling by default passes on to the page underneath. This is called scroll chaining. The overscroll-behavior: contain property stops it.
It is useful in chat windows, dropdown menus, side panels, and modals: scrolling their content doesnât move the page behind.
The none value additionally turns off effects of scrolling past the edge, such as the bounce on iPhone or the pull-down-to-refresh gesture on Android.
Syntax
#Syntax
overscroll-behavior: auto | contain | none (1-2 values);Values
#Values in practice
#auto
After reaching the end of the list, the outer container scrolls.
.demo { overscroll-behavior: auto; }contain
Scrolling stops at the list.
.demo { overscroll-behavior: contain; }none
Like contain, without effects of scrolling past the edge.
.demo { overscroll-behavior: none; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Every scrollable panel in a modal should have
overscroll-behavior: contain. - Setting
noneon thebodyelement turns off the pull-to-refresh gesture in web apps.
Related entries
#Spotted a mistake or missing an example? Write to us.