Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The overflow property

Reference for the CSS overflow property: visible, hidden, clip, scroll and auto, one or two values, effects on layout, examples and browser support.

The overflow property decides what happens when content is larger than its box: show it anyway, cut it off, or let the user scroll. It is a shorthand for overflow-x and overflow-y.

CSS
.panel {
  height: 8rem;
  overflow: auto;
}

Try it

Five overflow values

With visible the text spills out of its dashed box and may overlap what follows. hidden and clip cut it at the padding edge. scroll always shows scrollbars (where the platform draws them), and auto shows them only when needed.

Two values

Syntax

CSS
overflow: <overflow-x> <overflow-y>?

/* each value: */
visible | hidden | clip | scroll | auto

One value applies to both axes. Two values are read as x then y.

  • Initial value: visible
  • Applies to: block containers, flex containers and grid containers
  • Inherited: no
  • Animatable: no
  • Computed value: as specified, except that visible and clip compute to auto and hidden when the other axis is a different kind (see below)

Values

Value Description
visible Content is not clipped and can render outside the box.
hidden Content is clipped at the padding edge. The box is still a scroll container, so it can be scrolled by script or by focus, but the user gets no scrollbars.
clip Content is clipped at the padding edge (or the overflow-clip-margin edge), and no scrolling of any kind is possible. The box is not a scroll container.
scroll Content is clipped and scrollbars are always shown.
auto Content is clipped and scrollbars appear only when the content overflows.

Usage notes

  • Mixed values. visible or clip on one axis and a scrolling value (hidden, scroll, auto) on the other cannot be combined: visible becomes auto and clip becomes hidden. Only overflow: clip on both axes, or visible on both, keeps the unclipped behavior.
  • Side effects of non-visible values. hidden, scroll and auto create a new block formatting context. That contains floats and stops margin collapsing through the box, but it also clips things like dropdowns, focus outlines and box shadows of children.
  • position: sticky breaks. A sticky child sticks relative to its nearest scrolling ancestor. An ancestor with overflow: hidden or auto can make it appear to do nothing. overflow: clip avoids this, because the box is not a scroll container.
  • Always give a size. Scrolling needs a limited height or width. A box with height: auto simply grows to fit its content.
  • Accessibility. Make scrollable regions keyboard reachable. Browsers focus scrollable areas with the keyboard in recent versions, but adding tabindex="0" and an accessible name on key regions is safer.
  • Hiding the page scrollbar. Applying overflow: hidden to body is a common way to lock page scroll behind a modal.
  • Smooth, contained scrolling. Pair it with overscroll-behavior and scroll-behavior.

Browser support

visible, hidden, scroll and auto work in every browser. The clip keyword and the two-value syntax are supported in all current major browsers (Baseline 2022 for clip).