Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS overscroll-behavior-y Property

Posted in CSS Tutorial
Updated on Oct 07, 2024
By Mari Selvan
👁️ 14 - Views
⏳ 4 mins
💬 1 Comment
CSS overscroll-behavior-y Property

Photo Credit to CodeToFun

🙋 Introduction

The overscroll-behavior-y property in CSS is used to control the behavior of a scrolling container when the scroll position reaches the edge of the content along the vertical axis.

This property is particularly useful for preventing the default "bounce" or "pull-to-refresh" behavior on touch devices or when working with nested scrollable elements. By setting this property, developers can enhance the user experience by providing a more controlled and consistent scrolling behavior.

💡 Syntax

The syntax for the overscroll-behavior-y property is straightforward and can be applied to any scrollable container.

Syntax
Copied
Copy To Clipboard
element {
  overscroll-behavior-y: value;
}

🎛️ Default Value

The default value of the overscroll-behavior-y property is auto. This means the default scroll behavior of the browser will occur when the scroll reaches the edge of the content.

🏠 Property Values

ValueDescription
autoThe default behavior of the browser is maintained. Scroll events are propagated normally.
containThe scroll behavior is contained within the element. The element does not allow scrolling beyond the boundaries, and the default bounce or pull-to-refresh behavior is disabled.
noneAll scroll overflow effects are disabled. The element does not allow any scroll chaining or scroll overflow effects.

📄 Example

In this example, we prevent the vertical scroll overflow behavior on a container element.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS overscroll-behavior-y Example</title>
  <style>
    .scroll-container {
      width: 300px;
      height: 200px;
      overflow: auto;
      border: 1px solid #ccc;
      overscroll-behavior-y: contain;
    }
    .content {
      height: 400px;
      background: linear-gradient(#e66465, #9198e5);
    }
  </style>
</head>
<body>
  <h1>Overscroll Behavior Y Example</h1>
  <div class="scroll-container">
    <div class="content"></div>
  </div>
</body>
</html>

In this example, the .scroll-container has a fixed height with overflow enabled. The overscroll-behavior-y: contain; property ensures that the user cannot scroll beyond the top or bottom of the container, preventing the default bounce effect.

🖥️ Browser Compatibility

The overscroll-behavior-y property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Edge, and Opera. Safari does not fully support this property, so testing across different browsers is recommended for consistent behavior.

🎉 Conclusion

The overscroll-behavior-y property provides developers with greater control over the scrolling behavior of web pages and applications.

By using this property, you can create a smoother and more predictable scrolling experience, especially on touch devices. Experiment with the different values to see how they affect your layout and user interactions.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy