CSS Reference ยท Box Model and Sizing
The overflow-y property
Reference for the CSS overflow-y property: control what happens when content is taller than its box. Values, the overflow-x pairing rule, examples and support.
The overflow-y property decides what happens when an element's content is taller than the element itself. The content can spill out and stay visible, be cut off, or be reached by scrolling. It is the vertical half of the overflow shorthand.
.log { height: 8rem; overflow-y: auto; }
Try it
The visible box lets its text run past the border, the hidden box cuts it off, and the scroll and auto boxes can be scrolled. The scroll box always reserves room for a scrollbar track, while auto shows one only because the text really overflows.
Syntax
overflow-y: visible | hidden | clip | scroll | auto
- Initial value:
visible - Applies to: block containers, flex containers and grid containers
- Inherited: no
- Animatable: no (discrete)
- Computed value: as specified, except that
visibleorclipbecomeautoorhiddenwhen the other axis is a scrolling value
Values
| Value | Description |
|---|---|
visible |
Content is not clipped and can paint outside the box. |
hidden |
Content is clipped at the padding edge. It can still be scrolled by script (for example scrollTop) or by moving focus into it. |
clip |
Content is clipped, and no scrolling of any kind is possible, not even by script. It does not create a scroll container. |
scroll |
Content is clipped and the user can scroll. A scrollbar area is always shown where scrollbars take space. |
auto |
Like scroll, but scrollbars appear only when the content overflows. |
Usage notes
- The pairing rule. If one axis is
visibleand the other is not, thevisibleaxis computes toauto. Sooverflow-x: hiddentogether with the defaultoverflow-y: visiblegives you a vertical scrollbar when needed. The exception isclip, which can be mixed withvisible. hiddenandscrollcreate a scroll container. That also creates a new block formatting context, which contains floats and stops margins from collapsing through it.position: stickybreaks inside it. A sticky child sticks relative to its nearest scrolling ancestor, so anoverflow-y: autowrapper you did not intend can make it appear to stop working.- Give the box a height. A block with
height: autogrows to fit its content, so there is nothing to overflow. Setheight,max-heightor a flex/grid constraint. - Prefer
autooverscroll. Permanent scrollbar tracks look cluttered and shift the layout on platforms where scrollbars take space. - Accessibility. Keyboard users must be able to scroll a region. Browsers make many scrollable regions focusable automatically; if yours is not, add
tabindex="0"and an accessible name.
Browser support
overflow-y is supported in every browser; the clip value is also supported in all current browsers.
Related
overflowโ the shorthandoverflow-xโ the horizontal axisoverflow-wrapโ breaking long words instead of overflowingoverflow-anchor- Lesson: Overflow