CSS overflow-y Property
Description
The overflow-y
CSS property is used to control the vertical overflow behavior of an element when its content exceeds its defined height. It specifies how the content that overflows the element's vertical boundaries should be handled. You can set it to various values such as "visible" (default, content overflows the box), "hidden" (content is clipped and not visible), "scroll" (scrollbars appear when content overflows), or "auto" (scrollbars appear only when necessary). This property is particularly useful for maintaining the layout and appearance of web pages when dealing with long or dynamic content within a fixed-size container.
- Initial value
- visible
- Applies to
- Block containers, flex containers and grid containers
- Inherited
- No
- Computed value
- As specified
- Animatable
- No
- JavaScript syntax
- object.style.overflowY
Interactive Demo
Syntax
overflow-y: visible | hidden | scroll | auto
Values
- visibleContent is not clipped and scroll bars are not added. Elements are clipped to the size of the containing window or frame.
- hiddenContent that exceeds the dimensions of the object is not shown.
- scrollContent is clipped and scroll bars are added, even if the content does not exceed the dimensions of the object.
- autoContent is clipped and scrolling is added only when necessary.
Example
<div class="test"> visible
<img src="images/tech.gif" alt="">
</div>
<div class="test2"> hidden
<img src="images/tech.gif" alt="">
</div>
<div class="test3"> scroll
<img src="images/tech.gif" alt="">
</div>
<div class="test4"> auto
<img src="images/tech.gif" alt="">
</div>
div {
display: inline-block;
margin-right: 30px;
width: 100px;
height: 100px;
border: 2px solid blue;
}
img {
width: 125px;
height: 125px;
}
.test {
overflow-x: visible;
overflow-y: visible;
}
.test2 {
overflow-x: hidden;
overflow-y: hidden;
}
.test3 {
overflow-x: scroll;
overflow-y: scroll;
}
.test4 {
overflow-x: auto;
overflow-y: auto;
}
Browser Support
The following table will show you the current browser support for the CSS overflow-y
property.
Desktop | |||||
12 | 1 | 3.5 | 9.5 | 3 |
Tablets / Mobile | |||||
18 | 4 | 14 | 1 | 1 | 37 |
Last updated by CSSPortal on: 2nd January 2024