CSS overflow-y Property
The CSS overflow-y property controls how an element handles content that extends beyond its vertical boundaries.
It determines whether vertically overflowing content remains visible, is clipped, or can be accessed through scrolling. Common uses include scrollable panels, menus, message lists, and containers with limited height.
overflow-y Syntax
The overflow-y property accepts one keyword that determines how vertical overflow is handled.
Basic Syntax
selector {
overflow-y: auto;
}
Keyword Values
.box {
overflow-y: visible;
}
.box {
overflow-y: hidden;
}
.box {
overflow-y: clip;
}
.box {
overflow-y: scroll;
}
.box {
overflow-y: auto;
}
CSS-Wide Keywords
.box {
overflow-y: initial;
}
.box {
overflow-y: inherit;
}
.box {
overflow-y: unset;
}
.box {
overflow-y: revert;
}
.box {
overflow-y: revert-layer;
}
The initial value is visible. Its computed value can change depending on the value of overflow-x.
Property Values
| Value | Description |
|---|---|
visible |
Allows content to extend beyond the vertical boundary, subject to the overflow setting on the other axis. |
hidden |
Clips vertical overflow without providing a scrollbar. Programmatic scrolling remains possible. |
clip |
Clips vertical overflow at the overflow clip edge and prevents scrolling along that axis. |
scroll |
Creates a vertically scrollable region, even when the content currently fits. |
auto |
Allows vertical scrolling when content exceeds the available height. |
initial |
Resets the property to visible. |
inherit |
Uses the computed value of the parent element. |
unset |
Resets the property to visible 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 | visible |
| Inherited | No |
| Applies to | Block containers, flex containers, and grid containers |
| Computed value | Specified keyword, with adjustments based on the other overflow axis |
| Animation type | Discrete |
| Physical axis | Vertical (y-axis) |
| Length values | Not accepted |
| Percentage values | Not accepted |
Valid Values
.box {
overflow-y: visible;
}
.box {
overflow-y: hidden;
}
.box {
overflow-y: clip;
}
.box {
overflow-y: scroll;
}
.box {
overflow-y: auto;
}
Invalid Values
.box {
overflow-y: none;
}
.box {
overflow-y: 200px;
}
.box {
overflow-y: hidden auto;
}
The property accepts one overflow keyword, not a length or multiple overflow values.
How It Works
Vertical overflow occurs when content extends beyond the top or bottom boundary of an element's available space.
The overflow-y property determines whether the overflowing content remains visible, is clipped, or can be reached through scrolling.
Creating Vertical Overflow
.container {
height: 150px;
overflow-y: auto;
}
.content {
height: 350px;
}
The child is taller than the container, so vertical scrolling becomes available.
Clipping Vertical Overflow
.container {
height: 150px;
overflow-y: hidden;
}
.content {
height: 350px;
}
The portion of the child extending beyond the container's vertical boundary is clipped.
Allowing Visible Overflow
.container {
height: 150px;
overflow-y: visible;
}
.content {
height: 350px;
}
The child can extend beyond the container when the horizontal overflow setting permits visible overflow.
Important Consideration
For a typical block element, a constrained height or maximum height is needed to produce vertical overflow. Otherwise, the element may expand to accommodate its content.
Overflow Values
The five overflow keywords provide different behavior for content extending beyond an element's vertical boundaries.
visible
.box {
overflow-y: visible;
}
Allows vertical overflow to remain visible. This is the initial value.
hidden
.box {
overflow-y: hidden;
}
Clips overflowing content without displaying a vertical scrollbar. Scripts and certain browser navigation operations may still change the scroll position.
clip
.box {
overflow-y: clip;
}
Clips overflowing content at the overflow clip edge and prevents scrolling along the clipped axis.
scroll
.box {
overflow-y: scroll;
}
Creates a vertically scrollable region even when its content does not exceed the available height. Scrollbar visibility depends on the browser and operating system.
auto
.box {
overflow-y: auto;
}
Allows vertical scrolling when content exceeds the available height.
Choosing a Value
Use auto for content that should remain accessible through scrolling. Use clipping values only when hiding the excess content is intentional.
overflow-y vs. overflow-x
The overflow-y and overflow-x properties control overflow along separate physical axes.
| Property | Direction | Typical Use |
|---|---|---|
overflow-y |
Vertical | Scrollable panels, menus, and message lists |
overflow-x |
Horizontal | Wide tables, code blocks, and horizontal galleries |
Vertical Scrolling
.box {
overflow-x: hidden;
overflow-y: auto;
}
Horizontal Scrolling
.box {
overflow-x: auto;
overflow-y: hidden;
}
Scrolling Along Both Axes
.box {
overflow-x: auto;
overflow-y: auto;
}
Using the overflow Shorthand
.box {
overflow: hidden auto;
}
The first value sets overflow-x, while the second sets overflow-y.
Important Consideration
The two axes interact. Some specified overflow values are adjusted when the opposite axis uses a scrolling overflow value.
Computed Value Adjustments
The computed value of overflow-y can depend on the value of overflow-x.
visible with auto
.box {
overflow-x: auto;
overflow-y: visible;
}
The specified overflow-y: visible computes to auto because the horizontal axis uses auto.
clip with scroll
.box {
overflow-x: scroll;
overflow-y: clip;
}
The specified overflow-y: clip computes to hidden because the horizontal axis uses scroll.
Both Axes Using visible
.box {
overflow-x: visible;
overflow-y: visible;
}
Both values remain visible.
Both Axes Using clip
.box {
overflow-x: clip;
overflow-y: clip;
}
Both values remain clip.
Computed Value Rules
visiblecomputes toautowhen the opposite axis is neithervisiblenorclip.clipcomputes tohiddenunder the same condition.- When both axes use only
visibleandclip, those values remain unchanged.
These adjustments are important when attempting to clip or scroll content along only one axis.
Vertical Scrolling
Vertical scrolling allows content to remain accessible within a container that has limited height.
Fixed-Height Scroll Container
.scroll-panel {
height: 200px;
overflow-y: auto;
}
The panel becomes vertically scrollable when its content exceeds 200 pixels in height.
Maximum-Height Scroll Container
.scroll-panel {
max-height: 300px;
overflow-y: auto;
}
The panel can grow with its content until it reaches 300 pixels. Additional content then becomes scrollable.
Scroll Behavior
.scroll-panel {
max-height: 300px;
overflow-y: auto;
scroll-behavior: smooth;
}
The scroll-behavior property controls certain programmatic scrolling operations, not ordinary manual scrolling.
Scrollbar Gutter
.scroll-panel {
max-height: 300px;
overflow-y: auto;
scrollbar-gutter: stable;
}
The scrollbar-gutter property can reserve space for classic scrollbars, helping reduce layout changes when a scrollbar appears.
Important Consideration
A vertically scrollable region should have an appropriate height constraint and should not prevent users from reaching essential content.
Scrollable Panels
Scrollable panels are useful when a section contains more information than can comfortably fit within its available height.
Scrollable Menu
.menu-list {
max-height: 240px;
overflow-y: auto;
}
A long menu can remain within a limited area while allowing users to scroll to additional items.
Message List
.message-list {
height: 350px;
overflow-y: auto;
padding: 15px;
}
The message list can scroll independently of surrounding page content.
Sidebar
.sidebar {
max-height: 80vh;
overflow-y: auto;
}
The sidebar can remain within a height based on the viewport while allowing access to additional content.
Nested Scroll Regions
Nested scrolling can make navigation difficult, particularly on touch devices. Use independently scrollable regions only when they provide a clear benefit.
Important Consideration
Ensure that controls inside scrollable panels remain reachable with keyboard, pointer, and touch input.
hidden vs. clip
The hidden and clip values both conceal overflowing content, but they differ in scrolling behavior.
| Behavior | hidden | clip |
|---|---|---|
| Clips vertical overflow | Yes | Yes |
| Displays a vertical scrollbar | No | No |
| Allows programmatic scrolling along the affected axis | Yes | No |
| Creates a scroll container by itself | Yes | No |
Using hidden
.panel {
height: 150px;
overflow-y: hidden;
}
Content is clipped, but scripts may still adjust the vertical scroll position.
Using clip
.panel {
height: 150px;
overflow-y: clip;
}
Content is clipped without permitting scrolling along the clipped axis.
Important Consideration
The behavior of clip also depends on the other overflow axis. When the opposite axis uses a scrolling value, clip computes to hidden.
Physical vs. Logical Overflow
The overflow-y property always controls the physical vertical axis, regardless of writing mode.
The logical overflow-inline and overflow-block properties adapt to the element's writing mode.
| Property | Axis |
|---|---|
overflow-x |
Physical horizontal axis |
overflow-y |
Physical vertical axis |
overflow-inline |
Logical inline axis |
overflow-block |
Logical block axis |
Horizontal Writing Mode
.box {
writing-mode: horizontal-tb;
overflow-y: auto;
}
In horizontal writing, the physical y-axis corresponds to the block axis.
Vertical Writing Mode
.box {
writing-mode: vertical-rl;
overflow-y: auto;
}
In vertical writing, the physical y-axis corresponds to the inline axis.
Important Consideration
Use overflow-y when the desired direction is always vertical. Use logical overflow properties when the direction should adapt to writing mode, while accounting for their browser support.
overflow-y Example
This example compares the five overflow values using fixed-height containers containing more text than can fit vertically.
HTML Example
<div class="overflow-demo">
<div class="overflow-item">
<h3>visible</h3>
<div class="overflow-box overflow-visible">
<p>Line 1: Introduction</p>
<p>Line 2: Additional content</p>
<p>Line 3: More information</p>
<p>Line 4: Final paragraph</p>
</div>
</div>
<div class="overflow-item">
<h3>hidden</h3>
<div class="overflow-box overflow-hidden">
<p>Line 1: Introduction</p>
<p>Line 2: Additional content</p>
<p>Line 3: More information</p>
<p>Line 4: Final paragraph</p>
</div>
</div>
<div class="overflow-item">
<h3>clip</h3>
<div class="overflow-box overflow-clip">
<p>Line 1: Introduction</p>
<p>Line 2: Additional content</p>
<p>Line 3: More information</p>
<p>Line 4: Final paragraph</p>
</div>
</div>
<div class="overflow-item">
<h3>scroll</h3>
<div class="overflow-box overflow-scroll" tabindex="0">
<p>Line 1: Introduction</p>
<p>Line 2: Additional content</p>
<p>Line 3: More information</p>
<p>Line 4: Final paragraph</p>
</div>
</div>
<div class="overflow-item">
<h3>auto</h3>
<div class="overflow-box overflow-auto" tabindex="0">
<p>Line 1: Introduction</p>
<p>Line 2: Additional content</p>
<p>Line 3: More information</p>
<p>Line 4: Final paragraph</p>
</div>
</div>
</div>
CSS Example
.overflow-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 35px 20px;
padding: 20px;
background-color: #f1f5f9;
}
.overflow-item h3 {
margin: 0 0 10px;
font-size: 16px;
}
.overflow-box {
box-sizing: border-box;
height: 120px;
padding: 12px;
border: 2px solid #64748b;
background-color: #fff;
}
.overflow-box p {
margin: 0 0 12px;
}
.overflow-visible {
overflow-y: visible;
}
.overflow-hidden {
overflow-y: hidden;
}
.overflow-clip {
overflow-y: clip;
}
.overflow-scroll {
overflow-y: scroll;
}
.overflow-auto {
overflow-y: auto;
}
visible
Line 1: Introduction
Line 2: Additional content
Line 3: More information
Line 4: Final paragraph
hidden
Line 1: Introduction
Line 2: Additional content
Line 3: More information
Line 4: Final paragraph
clip
Line 1: Introduction
Line 2: Additional content
Line 3: More information
Line 4: Final paragraph
scroll
Line 1: Introduction
Line 2: Additional content
Line 3: More information
Line 4: Final paragraph
auto
Line 1: Introduction
Line 2: Additional content
Line 3: More information
Line 4: Final paragraph
The visible example allows content to extend below its container. The hidden and clip examples conceal the excess content, while scroll and auto allow vertical scrolling.
Scrollable Message Panel
This example demonstrates a practical vertically scrollable panel using overflow-y: auto.
<div class="message-panel" tabindex="0" role="region" aria-label="Message history">
<div class="message">Message 1: Welcome to the discussion.</div>
<div class="message">Message 2: Here is the first update.</div>
<div class="message">Message 3: Additional information is available.</div>
<div class="message">Message 4: Please review the details.</div>
<div class="message">Message 5: The final update is ready.</div>
</div>
.message-panel {
box-sizing: border-box;
width: 320px;
max-width: 100%;
height: 180px;
padding: 12px;
border: 2px solid #64748b;
background-color: #f8fafc;
overflow-y: auto;
}
.message {
margin-bottom: 10px;
padding: 10px;
background-color: #dbeafe;
border: 1px solid #93c5fd;
}
The panel maintains a fixed height while allowing users to scroll vertically to view all five messages.
Accessibility Considerations
Vertically scrollable regions should remain accessible through keyboard, pointer, and touch input.
Keyboard Access
Ensure users can scroll independently scrollable regions with a keyboard. Adding tabindex="0" may help when the region is not otherwise keyboard accessible.
<div class="scroll-panel" tabindex="0" role="region" aria-label="Scrollable information">
<p>Scrollable content</p>
</div>
Visible Focus Indicators
.scroll-panel:focus-visible {
outline: 3px solid #2563eb;
outline-offset: 2px;
}
Avoid Hiding Essential Content
Using hidden or clip can conceal information or controls that users need.
Limit Nested Scrolling
Multiple nested scroll regions can make navigation confusing. Use them only when necessary.
Test Zoom and Reflow
Check that content remains reachable when users increase text size or browser zoom.
Important Consideration
Use auto rather than clipping when users must be able to access content beyond the visible area.
Common Mistakes
Forgetting to Constrain Height
.box {
overflow-y: auto;
}
If the box expands to fit its content, vertical scrolling may not occur. Apply an appropriate height or maximum height when needed.
Confusing hidden and clip
hidden permits programmatic scrolling, while clip prevents scrolling along the clipped axis.
Expecting visible to Remain visible
.box {
overflow-x: auto;
overflow-y: visible;
}
The vertical value computes to auto because the horizontal axis uses a scrolling overflow value.
Using Invalid Values
.box {
overflow-y: none;
}
The none keyword is not valid for this property.
Assuming scroll Always Displays a Scrollbar
Overlay scrollbar systems may hide scrollbars until scrolling occurs, even when overflow-y: scroll is specified.
Hiding Important Content
Clipping content can prevent users from reaching information or interactive controls.
Ignoring Flex and Grid Sizing
Flex and grid items may need appropriate minimum sizing rules, such as min-height: 0, before an inner region can scroll as intended.
Important Considerations
Keep the following points in mind when using overflow-y:
- The property controls overflow along the physical vertical axis.
- Its initial value is
visible. - The property is not inherited.
- It accepts
visible,hidden,clip,scroll, andauto. - Only one overflow keyword is permitted.
visibleallows content to extend beyond the container.hiddenclips content but permits programmatic scrolling.clipclips content and prevents scrolling along the clipped axis.scrollcreates a scrollable region even when no overflow currently exists.autoallows scrolling when needed.- A height constraint is usually needed to produce vertical overflow in a typical block container.
- Scrollbar visibility depends on the browser and operating system.
- The value of
overflow-xcan affect the computed value ofoverflow-y. - The
overflowshorthand can set both axes. - The property remains vertical regardless of writing mode.
- Logical overflow properties adapt to writing mode.
- Vertical scrolling is useful for panels, menus, and message lists.
- Scrollable regions should remain keyboard accessible.
- Clipping should not conceal essential information.
- Nested scroll regions should be used carefully.
- Flex and grid sizing rules can affect whether scrolling occurs.
- Test scrolling with keyboard, pointer, touch, and increased zoom.
Browser Support
The CSS overflow-y property is Widely available across modern browsers.
The visible, hidden, scroll, and auto values have long-standing support. The clip value is supported in modern browsers but may not work in older versions.
Fallback Example
.box {
overflow-y: hidden;
overflow-y: clip;
}
Browsers that do not recognize clip can use hidden as a fallback. However, these values differ in programmatic scrolling behavior.
For current compatibility information, visit Can I Use? and search for overflow-y.
Specifications
The overflow-y property is defined in CSS Overflow Module Level 3.
CSS Overflow Module Level 3: Overflow Control
The specification defines overflow values, scrolling behavior, and interactions between the horizontal and vertical axes.
For additional documentation and examples, consult MDN Web Docs.
