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"
On this page

Example

#
CSS
.chat-messages {
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
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

#
  • auto

    After reaching the end of the list, the outer container scrolls.
  • contain

    Scrolling stops at the list.
  • none

    Like contain, without effects of scrolling past the edge.

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 none on the body element turns off the pull-to-refresh gesture in web apps.

Related entries

#

Spotted a mistake or missing an example? Write to us.