- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
CSS overscroll-behavior-x Control Horizontal Scroll
Use it to prevent unwanted scroll chaining and ensure a smoother user experience.
Options include 'auto', 'contain', and 'none'.
Introduction
The overscroll-behavior-x
CSS property controls how a browser handles horizontal scroll boundaries in a scrolling area. This is especially useful in web development to manage multiple scrolling areas and ensure they interact smoothly without unintended page scrolling.
Specification
The overscroll-behavior-x
property is defined in the CSS Overscroll Behavior Module Level 1. This module ensures consistent behavior across browsers, making it easier to create predictable scrolling experiences.
Description
The overscroll-behavior-x
CSS property helps manage how a scrolling area behaves when it reaches its horizontal boundary. By default, reaching the scroll boundary can cause the entire page to scroll, which can be disruptive in designs with multiple scrolling areas. This property offers a way to prevent this unwanted behavior, enhancing user experience and creating more controlled scrolling interactions.
Syntax
Using the overscroll-behavior-x
property is straightforward. Here’s an example of how to use it in CSS:
The property accepts keyword values (auto
, contain
, none
) and global values (inherit
, initial
, revert
, revert-layer
, unset
).
Values
The overscroll-behavior-x
property can take several values that control the scrolling behavior:
auto
: Default behavior, allowing the entire page to scroll when the boundary is reached.contain
: Stops scroll chaining to neighboring areas but allows default scroll overflow behavior within the element.none
: Prevents any scroll chaining and stops default scroll overflow behavior.inherit
: Inherits the value from the parent element.initial
: Sets the property to its initial value (auto
).revert
: Resets to the inherited value if it inherits, or to the initial value if not.revert-layer
: Resets to the inherited value if it inherits, or to the initial value if not, considering the cascade layer.unset
: Resets to the natural value, either inherited or initial.
Formal Definition
The overscroll-behavior-x
property is formally defined with the following characteristics:
Property | Value |
---|---|
Initial Value | auto |
Applies To | Non-replaced block-level elements and non-replaced inline-block elements |
Inherited | No |
Computed Value | As specified |
Animation Type | Discrete |
Formal Syntax
The formal syntax for the overscroll-behavior-x
property:
Examples
Preventing an Underlying Element from Scrolling Horizontally
In this example, there are two block-level boxes, one inside the other. The outer box has a large width, causing the page to scroll horizontally. The inner box has a small width but large content width, allowing it to scroll horizontally.
By default, reaching the inner box’s scroll boundary can cause the whole page to scroll. To prevent this, set overscroll-behavior-x: contain
on the inner box:
Example: overscroll-behavior-x: auto
This is the default behavior. When the inner element’s scroll boundary is reached, the entire page will start scrolling.
Output: Scrolling horizontally on the smaller element will cause the entire page to scroll.
Example: overscroll-behavior-x: contain
This prevents the underlying elements from scrolling when the inner element’s scroll boundary is reached.
Output: Scrolling horizontally on the smaller element will not cause the entire page to scroll.
Example: overscroll-behavior-x: none
This completely prevents any scroll chaining and default scroll overflow behavior.
Output: Scrolling horizontally on the smaller element will not affect the entire page.
Example: overscroll-behavior-x: initial
This sets the property to its initial value, which is auto
.
Output: Scrolling horizontally on the smaller element will cause the entire page to scroll, as it resets to the default behavior.
Specifications
The overscroll-behavior-x
property is defined in the CSS Overscroll Behavior Module Level 1 specification.
Specification |
---|
[CSS Overscroll Behavior Module Level 1]WebsiteUrl |
Browser Compatibility
The following table provides information about browser compatibility for the overscroll-behavior-x
property:
Browser | Version |
---|---|
Chrome | 63.0 |
Firefox | 59.0 |
Opera | 50.0 |
See Also
- [Take control of your scroll: customizing pull-to-refresh and overflow effects]WebsiteUrl
- The mapped logical properties: [
overscroll-behavior-inline
]WebsiteUrl, [overscroll-behavior-block
]WebsiteUrl
Talk with CEO
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.