CSS overscroll-behavior-y Property
The CSS overscroll-behavior-y property controls scroll chaining and overscroll effects along the vertical axis of a scroll container.
It determines what happens when users attempt to scroll beyond the top or bottom boundary of a scrollable element. This property is useful for dialogs, sidebars, dropdown menus, and other independently scrolling areas where additional vertical scrolling should not move surrounding content.
overscroll-behavior-y Syntax
The overscroll-behavior-y property accepts one keyword that determines how vertical overscroll is handled.
Basic Syntax
selector {
overscroll-behavior-y: contain;
}
Keyword Values
.panel {
overscroll-behavior-y: auto;
}
.panel {
overscroll-behavior-y: contain;
}
.panel {
overscroll-behavior-y: none;
}
CSS-Wide Keywords
.panel {
overscroll-behavior-y: initial;
}
.panel {
overscroll-behavior-y: inherit;
}
.panel {
overscroll-behavior-y: unset;
}
.panel {
overscroll-behavior-y: revert;
}
.panel {
overscroll-behavior-y: revert-layer;
}
The initial value is auto, which allows normal vertical scroll chaining and browser overscroll effects.
Property Values
| Value | Description |
|---|---|
auto |
Allows normal vertical scroll chaining and overscroll effects. |
contain |
Prevents vertical scroll chaining to ancestor scroll containers while allowing local overscroll effects. |
none |
Prevents vertical scroll chaining and suppresses local vertical overscroll effects. |
initial |
Resets the property to auto. |
inherit |
Uses the computed value of the parent element. |
unset |
Resets the property to auto because it 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 |
| Inherited | No |
| Applies to | Scroll containers |
| Computed value | Specified keyword |
| Animation type | Discrete |
| Controlled axis | Physical vertical axis (y-axis) |
| Logical equivalent | overscroll-behavior-block or overscroll-behavior-inline, depending on writing mode |
| Length values | Not accepted |
| Percentage values | Not accepted |
Valid Values
.panel {
overscroll-behavior-y: auto;
}
.panel {
overscroll-behavior-y: contain;
}
.panel {
overscroll-behavior-y: none;
}
Invalid Values
.panel {
overscroll-behavior-y: hidden;
}
.panel {
overscroll-behavior-y: 20px;
}
.panel {
overscroll-behavior-y: contain none;
}
The property accepts only one overscroll keyword. Use the overscroll-behavior shorthand when specifying separate horizontal and vertical values in one declaration.
How It Works
When users scroll vertically inside a scroll container, the browser moves the content until it reaches its top or bottom boundary.
Additional scrolling may then transfer to an ancestor scroll container or trigger an overscroll effect. The overscroll-behavior-y property determines whether those actions are allowed.
Default Behavior
.panel {
height: 200px;
overflow-y: auto;
overscroll-behavior-y: auto;
}
Vertical scrolling behaves normally. When the panel reaches its boundary, additional scrolling may move an ancestor container.
Preventing Vertical Scroll Chaining
.panel {
height: 200px;
overflow-y: auto;
overscroll-behavior-y: contain;
}
The panel remains scrollable, but additional vertical scrolling does not transfer to an ancestor at its boundary.
Suppressing Vertical Overscroll Effects
.panel {
height: 200px;
overflow-y: auto;
overscroll-behavior-y: none;
}
This prevents vertical scroll chaining and suppresses local vertical overscroll effects.
Important Consideration
The property does not create a scroll container or prevent ordinary scrolling. Use an appropriate overflow value to establish the intended scrolling behavior.
Vertical Scroll Chaining
Vertical scroll chaining occurs when a scroll container reaches its top or bottom boundary and additional scrolling continues into an ancestor scroll container.
Allowing Scroll Chaining
.inner-panel {
max-height: 200px;
overflow-y: auto;
overscroll-behavior-y: auto;
}
When the inner panel reaches its boundary, additional vertical scrolling may move the surrounding page or another scrollable ancestor.
Preventing Scroll Chaining
.inner-panel {
max-height: 200px;
overflow-y: auto;
overscroll-behavior-y: contain;
}
Scrolling remains within the inner panel until it reaches its boundary. Additional vertical scrolling does not chain to an ancestor.
Preventing Chaining and Local Effects
.inner-panel {
max-height: 200px;
overflow-y: auto;
overscroll-behavior-y: none;
}
The none value prevents scroll chaining and suppresses local overscroll effects.
Common Uses
- Scrollable dialogs and modal content.
- Independent sidebars.
- Dropdown menus with many items.
- Chat and notification panels.
- Nested vertical scrolling areas.
Important Consideration
Preventing scroll chaining does not lock the entire page. Users can still scroll the surrounding page directly when it is the active scrolling area.
Vertical Overscroll Effects
Some browsers display visual effects when users attempt to scroll beyond the top or bottom of a scroll container. Examples include elastic bouncing and glow effects.
Allowing Normal Effects
.panel {
overscroll-behavior-y: auto;
}
Normal vertical scroll chaining and overscroll effects remain available.
Allowing Local Effects
.panel {
overscroll-behavior-y: contain;
}
Vertical scroll chaining is prevented, but local overscroll effects may still appear.
Suppressing Local Effects
.panel {
overscroll-behavior-y: none;
}
Both vertical scroll chaining and local overscroll effects are suppressed.
Pull-to-Refresh Behavior
Some mobile browsers provide pull-to-refresh functionality when users overscroll at the top of a page. Applying overscroll-behavior-y: contain or none to the root scroll container can prevent this behavior in supporting browsers.
html {
overscroll-behavior-y: contain;
}
Use root-level overscroll restrictions carefully because they can change familiar browser gestures.
Browser Differences
Overscroll effects and pull-to-refresh behavior vary between browsers, operating systems, and input devices. Not every browser provides the same visual feedback or gesture handling.
Nested Scroll Containers
Nested vertical scroll containers demonstrate how overscroll-behavior-y controls scrolling at boundaries.
When an inner panel reaches its top or bottom boundary, additional scrolling may normally move an outer scroll container. Applying contain to the inner panel prevents this scroll chaining.
HTML Example
<div class="outer-panel">
<p>Outer content 1</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>
<p>Inner content 5</p>
</div>
<p>Outer content 2</p>
<p>Outer content 3</p>
</div>
CSS Example
.outer-panel {
height: 300px;
padding: 15px;
overflow-y: auto;
border: 2px solid #64748b;
}
.inner-panel {
height: 150px;
padding: 10px;
overflow-y: auto;
overscroll-behavior-y: contain;
border: 2px solid #2563eb;
}
.inner-panel p {
padding: 15px;
background-color: #dbeafe;
}
The inner panel remains vertically scrollable, but additional scrolling at its boundary does not transfer to the outer panel.
Important Consideration
The outer panel can still be scrolled directly. Overscroll containment only affects scroll chaining from the inner panel.
Physical vs. Logical Axes
The overscroll-behavior-y property always controls the physical vertical axis, regardless of writing mode.
| Property | Controlled Axis |
|---|---|
overscroll-behavior-x |
Physical horizontal axis |
overscroll-behavior-y |
Physical vertical axis |
overscroll-behavior-inline |
Logical inline axis |
overscroll-behavior-block |
Logical block axis |
Horizontal Writing Mode
.panel {
writing-mode: horizontal-tb;
overscroll-behavior-y: contain;
}
In horizontal writing mode, the y-axis corresponds to the logical block axis.
Vertical Writing Mode
.panel {
writing-mode: vertical-rl;
overscroll-behavior-y: contain;
}
In vertical writing mode, the y-axis corresponds to the logical inline axis.
Logical Alternative
.panel {
overscroll-behavior-block: contain;
}
Use overscroll-behavior-block when overscroll behavior should follow the logical block axis rather than a fixed vertical direction.
Important Consideration
Physical properties are useful when the scrolling direction must remain vertical or horizontal. Logical properties are useful when the scrolling direction should adapt to writing mode.
overscroll-behavior-y Example
This example compares the auto, contain, and none values using vertically scrollable panels.
Scroll inside each panel until reaching the bottom, then continue scrolling. The differences affect scroll chaining and local overscroll effects supported by the browser.
HTML Example
<div class="overscroll-y-demo">
<div class="overscroll-y-item">
<h3>auto</h3>
<div class="overscroll-y-panel overscroll-y-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-y-item">
<h3>contain</h3>
<div class="overscroll-y-panel overscroll-y-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-y-item">
<h3>none</h3>
<div class="overscroll-y-panel overscroll-y-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-y-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 20px;
padding: 20px;
background-color: #f1f5f9;
}
.overscroll-y-item h3 {
margin: 0 0 10px;
font-size: 16px;
}
.overscroll-y-panel {
box-sizing: border-box;
height: 160px;
padding: 12px;
overflow-y: auto;
border: 2px solid #64748b;
background-color: #fff;
}
.overscroll-y-panel p {
margin: 0 0 12px;
padding: 8px;
background-color: #dbeafe;
}
.overscroll-y-auto {
overscroll-behavior-y: auto;
}
.overscroll-y-contain {
overscroll-behavior-y: contain;
}
.overscroll-y-none {
overscroll-behavior-y: 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 vertically. Differences become apparent when scrolling continues beyond their boundaries, particularly when the surrounding page can also scroll.
Nested Vertical Scroll Example
This example places a vertically scrollable panel inside another vertical scroll container. The inner panel uses contain to prevent scroll chaining.
HTML Example
<div class="outer-y-scroll" tabindex="0">
<p>Outer content 1</p>
<div class="inner-y-scroll" tabindex="0">
<p>Inner content 1</p>
<p>Inner content 2</p>
<p>Inner content 3</p>
<p>Inner content 4</p>
<p>Inner content 5</p>
</div>
<p>Outer content 2</p>
<p>Outer content 3</p>
<p>Outer content 4</p>
</div>
CSS Example
.outer-y-scroll {
box-sizing: border-box;
height: 280px;
padding: 15px;
overflow-y: auto;
border: 2px solid #64748b;
background-color: #f8fafc;
}
.outer-y-scroll > p {
padding: 15px;
background-color: #e2e8f0;
}
.inner-y-scroll {
box-sizing: border-box;
height: 150px;
padding: 10px;
overflow-y: auto;
overscroll-behavior-y: contain;
border: 2px solid #2563eb;
background-color: #fff;
}
.inner-y-scroll p {
margin: 0 0 10px;
padding: 12px;
background-color: #dbeafe;
}
Outer content 1
Inner content 1
Inner content 2
Inner content 3
Inner content 4
Inner content 5
Outer content 2
Outer content 3
Outer content 4
Scroll inside the blue-bordered inner panel until reaching its bottom boundary. Continued vertical scrolling does not move the outer container. You can still scroll the outer container directly.
Accessibility Considerations
Scrollable regions should remain accessible regardless of their overscroll settings.
Maintain Keyboard Access
Ensure users can reach independently scrollable regions with a keyboard. Provide a focusable region when needed.
<div class="scroll-panel" tabindex="0" role="region" aria-label="Scrollable content">
<p>Scrollable information</p>
</div>
Provide Visible Focus Indicators
.scroll-panel:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 2px;
}
Avoid Scroll Traps
Excessive scroll containment can make nested scrolling feel restrictive. Use it when the scrolling area should behave independently, and ensure users can move focus to surrounding content.
Preserve Familiar Browser Gestures
Root-level overscroll restrictions may affect pull-to-refresh behavior on mobile devices. Consider whether changing this behavior benefits users.
Important Consideration
Preventing scroll chaining should not prevent users from reaching essential information or interactive controls.
Common Mistakes
Applying the Property Without a Scroll Container
.panel {
overscroll-behavior-y: contain;
}
This declaration does not create scrolling. Establish a scroll container with an appropriate overflow value.
Confusing Overscroll with Overflow
The overflow-y property controls vertical clipping and scrolling. The overscroll-behavior-y property controls behavior at vertical scroll boundaries.
Using Invalid Values
.panel {
overscroll-behavior-y: hidden;
}
The hidden keyword is invalid. Use auto, contain, or none.
Using Two Values
.panel {
overscroll-behavior-y: contain none;
}
This longhand accepts only one keyword. Use the shorthand when assigning different values to the horizontal and vertical axes.
Expecting contain to Suppress Every Effect
The contain value prevents scroll chaining but allows local overscroll effects. Use none to suppress those effects.
Confusing Physical and Logical Axes
The y-axis is always vertical. Logical properties such as overscroll-behavior-block follow the element's writing mode.
Expecting the Property to Lock Page Scrolling
Applying overscroll-behavior-y: contain to an inner panel does not disable direct scrolling of the surrounding page.
Important Considerations
Keep the following points in mind when using overscroll-behavior-y:
- The property controls overscroll behavior along the physical vertical axis.
- Its initial value is
auto. - It is not inherited.
- It applies to scroll containers.
- It accepts
auto,contain, andnone. - Only one keyword is permitted.
autoallows normal vertical scroll chaining and overscroll effects.containprevents vertical scroll chaining while allowing local overscroll effects.noneprevents vertical scroll chaining and suppresses local overscroll effects.- The property does not create a scroll container.
- It does not disable ordinary vertical scrolling.
- The y-axis remains vertical regardless of writing mode.
- Scrollable dialogs, sidebars, and menus are common use cases.
- Nested vertical scroll containers make scroll chaining easier to observe.
- Browser overscroll effects vary by platform.
- Root-level settings may affect pull-to-refresh behavior.
- Scrollable regions should remain keyboard accessible.
- Use containment only where independent scrolling is beneficial.
- Test behavior with mouse, touch, trackpad, and keyboard input.
Browser Support
The CSS overscroll-behavior-y property is Widely available across modern browsers.
Current major browser engines support the auto, contain, and none values. Older browsers may ignore the property and use their default vertical scroll chaining behavior.
Progressive Enhancement
.panel {
max-height: 250px;
overflow-y: auto;
}
@supports (overscroll-behavior-y: contain) {
.panel {
overscroll-behavior-y: contain;
}
}
The panel remains vertically scrollable when the property is unsupported. Supporting browsers additionally prevent vertical scroll chaining.
For current compatibility information, visit Can I Use? and search for overscroll-behavior-y.
Specifications
The overscroll-behavior-y property is defined in CSS Overscroll Behavior Module Level 1.
CSS Overscroll Behavior Module Level 1
The specification defines horizontal and vertical overscroll behavior, scroll chaining, and local overscroll effects.
For additional documentation and examples, consult MDN Web Docs.
