Skip to content
Tutorials Center
My learning

Topics

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.

CSS
.log {
  height: 8rem;
  overflow-y: auto;
}

Try it

Scroll only when needed

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

CSS
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 visible or clip become auto or hidden when 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 visible and the other is not, the visible axis computes to auto. So overflow-x: hidden together with the default overflow-y: visible gives you a vertical scrollbar when needed. The exception is clip, which can be mixed with visible.
  • hidden and scroll create a scroll container. That also creates a new block formatting context, which contains floats and stops margins from collapsing through it.
  • position: sticky breaks inside it. A sticky child sticks relative to its nearest scrolling ancestor, so an overflow-y: auto wrapper you did not intend can make it appear to stop working.
  • Give the box a height. A block with height: auto grows to fit its content, so there is nothing to overflow. Set height, max-height or a flex/grid constraint.
  • Prefer auto over scroll. 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.