CSS overscroll-behavior Property
The CSS overscroll-behavior property controls what happens when a scroll container reaches the end of its scrollable content.
It determines whether scrolling continues into an ancestor scroll container and whether the browser displays overscroll effects, such as bouncing or pull-to-refresh. This property is useful for scrollable panels, dialogs, menus, and other components that should scroll independently of the surrounding page.
overscroll-behavior Syntax
The overscroll-behavior property accepts one or two keywords. The first controls the horizontal axis, and the second controls the vertical axis.
Basic Syntax
selector {
overscroll-behavior: contain;
}
Single-Value Syntax
.panel {
overscroll-behavior: auto;
}
.panel {
overscroll-behavior: contain;
}
.panel {
overscroll-behavior: none;
}
A single value applies to both axes.
Two-Value Syntax
.panel {
overscroll-behavior: auto contain;
}
The first value controls horizontal overscroll behavior. The second controls vertical overscroll behavior.
CSS-Wide Keywords
.panel {
overscroll-behavior: initial;
}
.panel {
overscroll-behavior: inherit;
}
.panel {
overscroll-behavior: unset;
}
.panel {
overscroll-behavior: revert;
}
.panel {
overscroll-behavior: revert-layer;
}
The initial value is auto for both axes.
Property Values
| Value | Description |
|---|---|
auto |
Allows normal scroll chaining and browser overscroll effects. |
contain |
Prevents scroll chaining to ancestor scroll containers while allowing local overscroll effects. |
none |
Prevents scroll chaining and suppresses local overscroll effects. |
initial |
Resets both axes to auto. |
inherit |
Uses the computed values of the parent element. |
unset |
Resets both axes to auto because the property is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto auto |
| Inherited | No |
| Applies to | Scroll containers |
| Computed value | Specified keywords for each axis |
| Animation type | Discrete |
| Shorthand for | overscroll-behavior-x and overscroll-behavior-y |
| Length values | Not accepted |
| Percentage values | Not accepted |
Valid Values
.panel {
overscroll-behavior: auto;
}
.panel {
overscroll-behavior: contain;
}
.panel {
overscroll-behavior: none;
}
.panel {
overscroll-behavior: auto contain;
}
.panel {
overscroll-behavior: contain none;
}
Invalid Values
.panel {
overscroll-behavior: hidden;
}
.panel {
overscroll-behavior: 10px;
}
.panel {
overscroll-behavior: auto contain none;
}
Only the keywords auto, contain, and none are accepted, with a maximum of two values.
How It Works
When a user scrolls inside a scroll container, the browser moves the content until it reaches the beginning or end of its scrollable area.
If the user continues scrolling beyond that boundary, the browser may pass the scrolling action to an ancestor container or display an overscroll effect.
Default Behavior
.scroll-panel {
height: 200px;
overflow-y: auto;
overscroll-behavior: auto;
}
When the panel reaches its scroll boundary, additional scrolling may move the surrounding page.
Containing Scroll Behavior
.scroll-panel {
height: 200px;
overflow-y: auto;
overscroll-behavior: contain;
}
Scrolling stops at the panel's boundary instead of continuing into an ancestor scroll container.
Suppressing Overscroll Effects
.scroll-panel {
height: 200px;
overflow-y: auto;
overscroll-behavior: none;
}
Scroll chaining is prevented, and local overscroll effects are suppressed.
Important Consideration
The property does not create scrolling. The element must be a scroll container, typically using overflow: auto or overflow: scroll, for the property to affect its scrolling boundaries.
Scroll Chaining
Scroll chaining occurs when scrolling reaches the boundary of one scroll container and continues into an ancestor scroll container.
Example of Scroll Chaining
.inner-panel {
max-height: 200px;
overflow-y: auto;
overscroll-behavior: auto;
}
After the inner panel reaches its scroll limit, continued scrolling may move the outer page.
Preventing Scroll Chaining
.inner-panel {
max-height: 200px;
overflow-y: auto;
overscroll-behavior: contain;
}
The browser prevents the scroll action from continuing into an ancestor scroll container along the affected axes.
Using none
.inner-panel {
max-height: 200px;
overflow-y: auto;
overscroll-behavior: none;
}
This also prevents scroll chaining, while suppressing local overscroll effects.
Common Uses
- Scrollable dialog content.
- Sidebars with independent scrolling.
- Message and notification panels.
- Dropdown menus containing long lists.
- Nested scrolling interfaces.
Important Consideration
Preventing scroll chaining does not disable scrolling inside the element. Users can still scroll through its content until reaching a boundary.
Overscroll Effects
Some browsers provide visual or interactive effects when users attempt to scroll beyond a scroll container's boundary.
Examples include elastic bouncing, glow effects, and browser navigation gestures such as pull-to-refresh.
Allowing Overscroll Effects
.panel {
overscroll-behavior: auto;
}
The browser can use its normal overscroll behavior.
Containing Overscroll Effects
.panel {
overscroll-behavior: contain;
}
Local overscroll effects remain available, but scroll chaining is prevented. Certain browser navigation effects may also be suppressed.
Suppressing Overscroll Effects
.panel {
overscroll-behavior: none;
}
The browser suppresses local overscroll effects and prevents scroll chaining for the affected scroll container.
Browser Differences
Overscroll effects vary by browser, operating system, and input device. A browser may not display a visible bounce or glow effect even when the property is set to auto or contain.
Important Consideration
The property controls overscroll behavior at scrolling boundaries. It does not disable ordinary scrolling, mouse-wheel input, or touch interactions inside the scroll container.
Controlling Each Axis
The overscroll-behavior shorthand can control the horizontal and vertical axes independently.
Horizontal and Vertical Control
.panel {
overscroll-behavior: auto contain;
}
Horizontal overscroll uses auto, while vertical overscroll uses contain.
Preventing Horizontal Scroll Chaining
.gallery {
overflow-x: auto;
overscroll-behavior: contain auto;
}
Horizontal scroll chaining is prevented while vertical overscroll retains its default behavior.
Preventing Vertical Scroll Chaining
.panel {
overflow-y: auto;
overscroll-behavior: auto contain;
}
Vertical scroll chaining is prevented while horizontal overscroll retains its default behavior.
Using Longhand Properties
.panel {
overscroll-behavior-x: auto;
overscroll-behavior-y: contain;
}
This produces the same result as overscroll-behavior: auto contain.
Logical Axis Properties
.panel {
overscroll-behavior-inline: contain;
overscroll-behavior-block: auto;
}
The logical properties follow the element's writing mode rather than fixed physical directions.
Important Consideration
For the shorthand, the first value always controls the physical x-axis, and the second controls the physical y-axis.
Nested Scroll Containers
Nested scroll containers occur when one scrollable element is placed inside another scrollable element.
Without overscroll control, reaching the boundary of the inner container may cause the outer container to scroll.
HTML Example
<div class="outer-panel">
<p>Outer panel content</p>
<div class="inner-panel">
<p>Inner content 1</p>
<p>Inner content 2</p>
<p>Inner content 3</p>
<p>Inner content 4</p>
</div>
<p>Additional outer content</p>
</div>
CSS Example
.outer-panel {
height: 300px;
overflow-y: auto;
}
.inner-panel {
height: 150px;
overflow-y: auto;
overscroll-behavior-y: contain;
}
The inner panel scrolls independently. When it reaches its vertical boundary, continued scrolling does not automatically move the outer panel.
Using the Shorthand
.inner-panel {
overscroll-behavior: contain;
}
This prevents scroll chaining along both axes.
Important Consideration
Use overscroll containment selectively. Blocking scroll chaining on every nested container can make navigation less convenient.
Page Overscroll
The overscroll-behavior property can also be used on the root scroll container to influence browser overscroll effects.
Preventing Vertical Overscroll Effects
html {
overscroll-behavior-y: none;
}
In supporting browsers, this can suppress vertical overscroll effects, including pull-to-refresh behavior where the browser exposes it as an overscroll action.
Containing Page Overscroll
html {
overscroll-behavior: contain;
}
This requests containment of overscroll behavior on both axes.
Using none on Both Axes
html {
overscroll-behavior: none;
}
This suppresses overscroll effects on both axes in supporting browsers.
Important Consideration
Browser-level gestures are not controlled identically across all platforms. Test root-level overscroll behavior on the browsers and devices your site supports.
overscroll-behavior Example
This example compares auto, contain, and none using scrollable panels.
Scroll inside each panel until you reach the bottom, then continue scrolling. Depending on your browser and input device, you may notice differences in scroll chaining or overscroll effects.
HTML Example
<div class="overscroll-demo">
<div class="overscroll-item">
<h3>auto</h3>
<div class="overscroll-panel overscroll-auto" tabindex="0">
<p>Item 1</p>
<p>Item 2</p>
<p>Item 3</p>
<p>Item 4</p>
<p>Item 5</p>
<p>Item 6</p>
</div>
</div>
<div class="overscroll-item">
<h3>contain</h3>
<div class="overscroll-panel overscroll-contain" tabindex="0">
<p>Item 1</p>
<p>Item 2</p>
<p>Item 3</p>
<p>Item 4</p>
<p>Item 5</p>
<p>Item 6</p>
</div>
</div>
<div class="overscroll-item">
<h3>none</h3>
<div class="overscroll-panel overscroll-none" tabindex="0">
<p>Item 1</p>
<p>Item 2</p>
<p>Item 3</p>
<p>Item 4</p>
<p>Item 5</p>
<p>Item 6</p>
</div>
</div>
</div>
CSS Example
.overscroll-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 20px;
padding: 20px;
background-color: #f1f5f9;
}
.overscroll-item h3 {
margin: 0 0 10px;
font-size: 16px;
}
.overscroll-panel {
box-sizing: border-box;
height: 160px;
padding: 12px;
overflow-y: auto;
border: 2px solid #64748b;
background-color: #fff;
}
.overscroll-panel p {
margin: 0 0 12px;
padding: 8px;
background-color: #dbeafe;
}
.overscroll-auto {
overscroll-behavior: auto;
}
.overscroll-contain {
overscroll-behavior: contain;
}
.overscroll-none {
overscroll-behavior: none;
}
auto
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
contain
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
none
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
All three panels scroll normally while content remains available. The differences become apparent when scrolling reaches a boundary.
Nested Scroll Panel Example
The following example uses an outer scroll container with a smaller inner container. The inner panel prevents vertical scroll chaining.
<div class="outer-scroll">
<p>Outer content above the panel</p>
<div class="inner-scroll" tabindex="0">
<p>Inner item 1</p>
<p>Inner item 2</p>
<p>Inner item 3</p>
<p>Inner item 4</p>
<p>Inner item 5</p>
</div>
<p>Outer content below the panel</p>
<p>Additional outer content</p>
</div>
.outer-scroll {
height: 260px;
padding: 15px;
overflow-y: auto;
border: 2px solid #64748b;
}
.inner-scroll {
height: 130px;
padding: 10px;
overflow-y: auto;
overscroll-behavior-y: contain;
background-color: #dbeafe;
}
.inner-scroll p {
margin: 0 0 12px;
padding: 8px;
background-color: #fff;
}
Outer content above the panel
Inner item 1
Inner item 2
Inner item 3
Inner item 4
Inner item 5
Outer content below the panel
Additional outer content
More outer content to demonstrate scrolling
Final outer paragraph
Scroll inside the blue inner panel. When it reaches its boundary, continued scrolling does not chain to the outer panel. The outer panel can still be scrolled directly.
Accessibility Considerations
Overscroll containment should improve scrolling behavior without making content difficult to navigate.
Maintain Keyboard Access
Scrollable regions should remain accessible through keyboard navigation. Use appropriate focus management and visible focus indicators.
.scroll-panel:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 2px;
}
Avoid Unnecessary Scroll Traps
Preventing scroll chaining can make scrolling feel restricted when users expect the surrounding page to move. Apply containment only where independent scrolling is helpful.
Preserve Content Access
The property should not be used as a substitute for proper overflow sizing. Ensure users can still reach all content inside the scroll container.
Test Different Input Methods
Check behavior with mouse wheels, touch gestures, trackpads, and keyboards. Overscroll effects may vary between devices.
Important Consideration
Use contain or none only when preventing scroll chaining or overscroll effects provides a clear benefit.
Common Mistakes
Applying the Property to a Non-Scrollable Element
.box {
overscroll-behavior: contain;
}
If the element is not a scroll container, the property does not create scrolling or establish a useful scroll boundary.
Confusing overscroll-behavior with overflow
The overflow property controls whether content is clipped or scrollable. The overscroll-behavior property controls behavior at scroll boundaries.
Using Invalid Values
.box {
overscroll-behavior: hidden;
}
The hidden keyword is not supported.
Reversing the Two Axes
.box {
overscroll-behavior: contain auto;
}
The first value controls horizontal overscroll, not vertical overscroll.
Expecting contain to Remove Every Overscroll Effect
The contain value prevents scroll chaining but can preserve local overscroll effects. Use none when those effects must also be suppressed.
Applying none Everywhere
Disabling overscroll behavior throughout a page may interfere with familiar browser scrolling interactions.
Assuming Identical Browser Behavior
Overscroll effects and browser gestures differ across platforms. Test the intended behavior on relevant devices.
Important Considerations
Keep the following points in mind when using overscroll-behavior:
- The property controls behavior when scrolling reaches a boundary.
- Its initial value is
autoon both axes. - The property is not inherited.
- It applies to scroll containers.
- It accepts
auto,contain, andnone. - One value applies to both axes.
- Two values control the horizontal and vertical axes separately.
autoallows normal scroll chaining and overscroll effects.containprevents scroll chaining while allowing local overscroll effects.noneprevents scroll chaining and suppresses local overscroll effects.- The property does not create a scroll container.
- It does not disable ordinary scrolling inside the container.
- It is a shorthand for
overscroll-behavior-xandoverscroll-behavior-y. - Logical longhands are available for writing-mode-aware behavior.
- Nested scroll containers are a common use case.
- Browser overscroll effects vary by platform.
- Root-level overscroll behavior can affect certain browser gestures.
- Scrollable regions should remain keyboard accessible.
- Excessive scroll containment can make navigation less convenient.
- Test behavior with mouse, touch, trackpad, and keyboard input.
Browser Support
The CSS overscroll-behavior property is Widely available across modern browsers.
The auto, contain, and none values are supported in current major browser engines. Older browsers may ignore the property and use their default scroll chaining behavior.
Progressive Enhancement
.scroll-panel {
max-height: 250px;
overflow-y: auto;
}
@supports (overscroll-behavior: contain) {
.scroll-panel {
overscroll-behavior: contain;
}
}
The panel remains scrollable when the property is unsupported. Supporting browsers additionally prevent scroll chaining.
For current compatibility information, visit Can I Use? and search for overscroll-behavior.
Specifications
The overscroll-behavior property is defined in CSS Overscroll Behavior Module Level 1.
CSS Overscroll Behavior Module Level 1
The specification defines scroll chaining, overscroll behavior, and the physical and logical properties used to control scrolling boundaries.
For additional documentation and examples, consult MDN Web Docs.
