CSS overscroll-behavior-x Property
The CSS overscroll-behavior-x property controls scroll chaining and overscroll effects along the horizontal axis of a scroll container.
It determines what happens when users attempt to scroll beyond the left or right boundary of a scrollable element. This property is useful for horizontal navigation menus, image galleries, carousels, and nested scrolling areas where additional horizontal scrolling should not affect surrounding content.
overscroll-behavior-x Syntax
The overscroll-behavior-x property accepts one keyword that determines how horizontal overscroll is handled.
Basic Syntax
selector {
overscroll-behavior-x: contain;
}
Keyword Values
.gallery {
overscroll-behavior-x: auto;
}
.gallery {
overscroll-behavior-x: contain;
}
.gallery {
overscroll-behavior-x: none;
}
CSS-Wide Keywords
.gallery {
overscroll-behavior-x: initial;
}
.gallery {
overscroll-behavior-x: inherit;
}
.gallery {
overscroll-behavior-x: unset;
}
.gallery {
overscroll-behavior-x: revert;
}
.gallery {
overscroll-behavior-x: revert-layer;
}
The initial value is auto, which allows normal horizontal scroll chaining and browser overscroll effects.
Property Values
| Value | Description |
|---|---|
auto |
Allows normal horizontal scroll chaining and overscroll effects. |
contain |
Prevents horizontal scroll chaining to ancestor scroll containers while allowing local overscroll effects. |
none |
Prevents horizontal scroll chaining and suppresses local horizontal 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 horizontal axis (x-axis) |
| Logical equivalent | overscroll-behavior-inline or overscroll-behavior-block, depending on writing mode |
| Length values | Not accepted |
| Percentage values | Not accepted |
Valid Values
.gallery {
overscroll-behavior-x: auto;
}
.gallery {
overscroll-behavior-x: contain;
}
.gallery {
overscroll-behavior-x: none;
}
Invalid Values
.gallery {
overscroll-behavior-x: hidden;
}
.gallery {
overscroll-behavior-x: 20px;
}
.gallery {
overscroll-behavior-x: contain none;
}
The property accepts only one overscroll keyword. Two values are permitted by the overscroll-behavior shorthand, not by this longhand.
How It Works
When users scroll horizontally inside a scroll container, the browser moves the content until it reaches its left or right boundary.
Additional scrolling may then transfer to an ancestor scroll container or trigger an overscroll effect. The overscroll-behavior-x property determines whether those actions are allowed.
Default Behavior
.gallery {
display: flex;
gap: 15px;
overflow-x: auto;
overscroll-behavior-x: auto;
}
Horizontal scrolling behaves normally. At a boundary, additional scrolling may continue into an ancestor container or produce a browser overscroll effect.
Preventing Horizontal Scroll Chaining
.gallery {
display: flex;
gap: 15px;
overflow-x: auto;
overscroll-behavior-x: contain;
}
Horizontal scrolling remains available inside the gallery, but it does not chain to an ancestor when the gallery reaches its boundary.
Suppressing Horizontal Overscroll Effects
.gallery {
display: flex;
gap: 15px;
overflow-x: auto;
overscroll-behavior-x: none;
}
This prevents horizontal scroll chaining and suppresses local overscroll effects.
Important Consideration
The property does not create a scroll container. Use an appropriate overflow value and ensure the content can overflow horizontally.
Horizontal Scroll Chaining
Horizontal scroll chaining occurs when a scroll container reaches its horizontal boundary and additional scrolling continues into an ancestor scroll container.
Allowing Scroll Chaining
.inner-gallery {
overflow-x: auto;
overscroll-behavior-x: auto;
}
When the gallery reaches its horizontal boundary, additional horizontal scrolling may move an ancestor scroll container.
Preventing Scroll Chaining
.inner-gallery {
overflow-x: auto;
overscroll-behavior-x: contain;
}
Scrolling remains inside the gallery and does not continue into an ancestor along the horizontal axis.
Using none
.inner-gallery {
overflow-x: auto;
overscroll-behavior-x: none;
}
This prevents horizontal scroll chaining and suppresses local overscroll effects.
Common Uses
- Horizontal navigation menus.
- Image galleries and carousels.
- Scrollable tab lists.
- Wide tables and code examples.
- Nested horizontal scrolling panels.
Important Consideration
Scroll chaining is most noticeable when an ancestor also supports scrolling along the horizontal axis. A vertically scrolling page may not provide an obvious comparison.
Horizontal Overscroll Effects
Some browsers display visual effects when users attempt to scroll beyond a horizontal boundary. Examples include elastic bouncing or glow effects.
Allowing Normal Effects
.gallery {
overscroll-behavior-x: auto;
}
Normal horizontal scroll chaining and overscroll effects remain available.
Allowing Local Effects
.gallery {
overscroll-behavior-x: contain;
}
Horizontal scroll chaining is prevented, but local overscroll effects may still appear.
Suppressing Local Effects
.gallery {
overscroll-behavior-x: none;
}
Both horizontal scroll chaining and local overscroll effects are suppressed.
Browser Navigation Gestures
Some browsers support horizontal gestures for navigating backward or forward through browsing history. Overscroll containment on the root scroll container may affect these gestures in supporting browsers.
Browser Differences
Overscroll effects and navigation gestures vary between browsers, operating systems, and input devices. Not every browser displays a visible effect when the value is auto.
Nested Scroll Containers
Nested horizontal scroll containers are useful for demonstrating how scroll chaining works.
When the inner container reaches its boundary, additional scrolling may normally move the outer container. Applying overscroll-behavior-x: contain to the inner container prevents this behavior.
HTML Example
<div class="outer-gallery">
<div class="outer-content">Outer item 1</div>
<div class="inner-gallery">
<div>Inner item 1</div>
<div>Inner item 2</div>
<div>Inner item 3</div>
<div>Inner item 4</div>
</div>
<div class="outer-content">Outer item 2</div>
</div>
CSS Example
.outer-gallery {
display: flex;
align-items: center;
gap: 20px;
width: 100%;
overflow-x: auto;
}
.outer-content {
flex: 0 0 200px;
}
.inner-gallery {
display: flex;
gap: 10px;
flex: 0 0 250px;
overflow-x: auto;
overscroll-behavior-x: contain;
}
.inner-gallery > div {
flex: 0 0 150px;
}
The inner gallery scrolls horizontally without passing additional horizontal scrolling to the outer gallery at its boundary.
Important Consideration
Preventing scroll chaining does not prevent users from scrolling the outer container directly. It only controls how scrolling behaves when the inner container reaches a boundary.
Physical vs. Logical Axes
The overscroll-behavior-x property always controls the physical horizontal 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-x: contain;
}
In horizontal writing mode, the x-axis corresponds to the logical inline axis.
Vertical Writing Mode
.panel {
writing-mode: vertical-rl;
overscroll-behavior-x: contain;
}
In vertical writing mode, the x-axis corresponds to the logical block axis.
Logical Alternative
.panel {
overscroll-behavior-inline: contain;
}
Use the logical property when overscroll behavior should follow inline progression rather than a fixed physical direction.
Important Consideration
The direction property can change whether inline content progresses left-to-right or right-to-left, but it does not change the physical orientation of the x-axis.
overscroll-behavior-x Example
This example compares auto, contain, and none using horizontally scrollable panels.
Scroll each panel to its horizontal boundary and continue scrolling. Differences in scroll chaining or local overscroll effects depend on the browser and input device.
HTML Example
<div class="overscroll-x-demo">
<div class="overscroll-x-item">
<h3>auto</h3>
<div class="overscroll-x-panel overscroll-x-auto" tabindex="0">
<span>Item 1</span>
<span>Item 2</span>
<span>Item 3</span>
<span>Item 4</span>
<span>Item 5</span>
</div>
</div>
<div class="overscroll-x-item">
<h3>contain</h3>
<div class="overscroll-x-panel overscroll-x-contain" tabindex="0">
<span>Item 1</span>
<span>Item 2</span>
<span>Item 3</span>
<span>Item 4</span>
<span>Item 5</span>
</div>
</div>
<div class="overscroll-x-item">
<h3>none</h3>
<div class="overscroll-x-panel overscroll-x-none" tabindex="0">
<span>Item 1</span>
<span>Item 2</span>
<span>Item 3</span>
<span>Item 4</span>
<span>Item 5</span>
</div>
</div>
</div>
CSS Example
.overscroll-x-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 20px;
padding: 20px;
background-color: #f1f5f9;
}
.overscroll-x-item {
min-width: 0;
}
.overscroll-x-item h3 {
margin: 0 0 10px;
font-size: 16px;
}
.overscroll-x-panel {
display: flex;
gap: 10px;
box-sizing: border-box;
padding: 12px;
overflow-x: auto;
border: 2px solid #64748b;
background-color: #fff;
}
.overscroll-x-panel span {
flex: 0 0 100px;
padding: 15px 10px;
background-color: #dbeafe;
text-align: center;
}
.overscroll-x-auto {
overscroll-behavior-x: auto;
}
.overscroll-x-contain {
overscroll-behavior-x: contain;
}
.overscroll-x-none {
overscroll-behavior-x: none;
}
auto
contain
none
All three panels scroll horizontally. The differences occur at their scroll boundaries, where additional scrolling may chain to an ancestor or produce a local overscroll effect.
Nested Horizontal Scroll Example
This example places a horizontally scrollable gallery inside another horizontal scroll container.
<div class="outer-x-scroll" tabindex="0">
<div class="outer-x-item">Outer item 1</div>
<div class="inner-x-scroll" tabindex="0">
<span>Inner 1</span>
<span>Inner 2</span>
<span>Inner 3</span>
<span>Inner 4</span>
<span>Inner 5</span>
</div>
<div class="outer-x-item">Outer item 2</div>
</div>
.outer-x-scroll {
display: flex;
align-items: center;
gap: 20px;
box-sizing: border-box;
max-width: 100%;
padding: 15px;
overflow-x: auto;
border: 2px solid #64748b;
}
.outer-x-item {
flex: 0 0 180px;
padding: 20px;
background-color: #e2e8f0;
}
.inner-x-scroll {
display: flex;
gap: 10px;
flex: 0 0 250px;
min-width: 0;
padding: 10px;
overflow-x: auto;
overscroll-behavior-x: contain;
border: 2px solid #2563eb;
}
.inner-x-scroll span {
flex: 0 0 100px;
padding: 15px 10px;
background-color: #dbeafe;
text-align: center;
}
Scroll horizontally inside the blue-bordered inner gallery. When it reaches either boundary, overscroll-behavior-x: contain prevents horizontal scroll chaining into the outer container. The outer container remains independently scrollable.
Accessibility Considerations
Horizontal scroll containers should remain usable with keyboards, touchscreens, trackpads, and other input devices.
Maintain Keyboard Access
Ensure users can reach scrollable regions and navigate their contents without relying exclusively on horizontal gestures.
<div class="gallery" tabindex="0" role="region" aria-label="Scrollable image gallery">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
Provide Visible Focus Indicators
.gallery:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 2px;
}
Provide Alternative Navigation Controls
For carousels and complex horizontal interfaces, consider visible previous and next controls so users do not need to rely on swipe gestures.
Avoid Unnecessary Scroll Containment
Preventing scroll chaining can improve independent scrolling, but excessive containment may make navigation less intuitive.
Important Consideration
The property should not prevent users from reaching content or controls within a horizontal scroll container.
Common Mistakes
Applying the Property Without Horizontal Scrolling
.gallery {
overscroll-behavior-x: contain;
}
The property does not create horizontal scrolling. Establish a scroll container using an appropriate overflow value.
Confusing Overscroll with Overflow
The overflow-x property controls horizontal clipping and scrolling. The overscroll-behavior-x property controls behavior at horizontal scroll boundaries.
Using Invalid Values
.gallery {
overscroll-behavior-x: hidden;
}
The hidden keyword is not valid. Use auto, contain, or none.
Using Two Values
.gallery {
overscroll-behavior-x: contain none;
}
This longhand accepts only one keyword. Use the shorthand to specify separate horizontal and vertical values.
Expecting contain to Remove Every Overscroll Effect
The contain value prevents scroll chaining but allows local overscroll effects. Use none when those effects should also be suppressed.
Confusing Physical and Logical Axes
The x-axis is always horizontal. Logical properties such as overscroll-behavior-inline follow the element's writing mode.
Expecting a Visible Difference on Every Device
Overscroll effects vary by platform. Differences may be difficult to observe without an ancestor that also scrolls horizontally.
Important Considerations
Keep the following points in mind when using overscroll-behavior-x:
- The property controls overscroll behavior along the physical horizontal axis.
- Its initial value is
auto. - The property is not inherited.
- It applies to scroll containers.
- It accepts
auto,contain, andnone. - Only one keyword is permitted.
autoallows normal horizontal scroll chaining and overscroll effects.containprevents horizontal scroll chaining while allowing local overscroll effects.noneprevents horizontal scroll chaining and suppresses local overscroll effects.- The property does not create a scroll container.
- It does not disable ordinary horizontal scrolling.
- The x-axis remains horizontal regardless of writing mode.
- Horizontal galleries and carousels are common use cases.
- Nested horizontal scroll containers make scroll chaining easier to observe.
- Browser overscroll effects vary by platform.
- Root-level overscroll settings may affect browser navigation gestures.
- 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-x 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 horizontal scroll chaining behavior.
Progressive Enhancement
.gallery {
display: flex;
overflow-x: auto;
}
@supports (overscroll-behavior-x: contain) {
.gallery {
overscroll-behavior-x: contain;
}
}
The gallery remains horizontally scrollable when the property is unsupported. Supporting browsers additionally prevent horizontal scroll chaining.
For current compatibility information, visit Can I Use? and search for overscroll-behavior-x.
Specifications
The overscroll-behavior-x 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.
