Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS overflow-y Property

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

Photo Credit to CodeToFun

🙋 Introduction

The overflow-y property in CSS controls the vertical overflow of content in an element. It determines what happens if content overflows the element's box vertically.

This property is useful for managing content within a fixed-height container and ensuring that the user experience remains smooth and consistent, even when the content is too large to fit in the available space.

💡 Syntax

The syntax for the overflow-y property is simple. It is used with any element that might have content that exceeds its bounds.

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

Here, value can be one of several keywords that control how the overflow is handled.

🎛️ Default Value

The default value of the overflow-y property is visible. This means that content is not clipped and can overflow the element's box, potentially causing it to expand.

🏠 Property Values

ValueDescription
visibleThe default value. Content is not clipped and may overflow the element's box.
hiddenThe content is clipped and any overflow is not visible. No scrollbars are provided.
scrollThe content is clipped, and a scrollbar is added to allow the user to scroll through the overflowed content.
autoIf the content overflows, a scrollbar will appear. Otherwise, no scrollbar is shown.

📄 Example

In this example, we'll use the overflow-y property to add a vertical scrollbar to a box containing too much text.

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 overflow-y Example</title>
  <style>
    .overflow-box {
      width: 200px;
      height: 100px;
      border: 1px solid #000;
      overflow-y: scroll;
    }
  </style>
</head>
<body>
  <h1>Box with Vertical Scroll</h1>
  <div class="overflow-box">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non nulla ut nunc fermentum dapibus. Vestibulum in massa leo. Duis vehicula risus non mauris viverra, vel aliquam nunc scelerisque.</p>
    <p>Maecenas et ligula sit amet neque consequat aliquet. Nullam varius eros at eros efficitur, eget bibendum odio efficitur.</p>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The overflow-y property is widely supported across all major browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is a reliable property to use when managing vertical overflow content.

🎉 Conclusion

The overflow-y property is an essential tool for controlling how content behaves when it exceeds the vertical limits of its container.

By using this property, you can ensure that your website's layout remains consistent and user-friendly, even with dynamic or extensive content. Experiment with the different values to see how they can best suit your design needs.

👨‍💻 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