CSS propertyBox model

overflow

Decides what happens to content that doesn’t fit in an element.

Initial value
visible
Inherited
No
Animatable
no
Applies to
block containers, flex containers, and grid containers
JavaScript
element.style.overflow = "auto"
On this page

Example

#
CSS
.table-wrapper {
  overflow-x: auto;
}
Preview

Definition and usage

#

The overflow property controls the behavior of content that extends past an element’s dimensions. By default (visible) it spills outside. You can also clip it, always show scrollbars, or show them only when needed.

It’s shorthand for overflow-x and overflow-y. Giving two values sets the horizontal and vertical axes separately, for example horizontal-only scrolling for a wide table.

Values other than visible and clip create a new scroll container. That has side effects: for example, an ancestor with overflow: hidden disables position: sticky on its descendants.

Syntax

#
Syntax
overflow: visible | hidden | clip | scroll | auto (1-2 values);

Values

#
  • visible

    The content spills outside the element.
  • hidden

    The overflow is clipped, but it can still be scrolled with a script.
  • auto

    A scrollbar appears only when the content doesn’t fit.
  • scroll

    Scrollbars are always visible (depending on the system).
  • clip

    Clips without creating a scroll container, so it doesn’t break position: sticky.

Values in practice

#

visible

The content spills outside the element.
.demo { overflow: visible; }

hidden

The overflow is clipped, but it can still be scrolled with a script.
.demo { overflow: hidden; }

auto

A scrollbar appears only when the content doesn’t fit.
.demo { overflow: auto; }

scroll

Scrollbars are always visible (depending on the system).
.demo { overflow: scroll; }

clip

Clips without creating a scroll container, so it doesn’t break position: sticky.
.demo { overflow: clip; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Wrap wide tables on phones in an element with overflow-x: auto, instead of squeezing the columns.
  • If position: sticky stopped working, look for an ancestor with overflow: hidden and switch it to overflow: clip.

Related entries

#

Spotted a mistake or missing an example? Write to us.