CSS propertyBox model

overflow-x

Decides what happens to content overflowing horizontally. Its twin overflow-y does the same vertically.

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

Example

#
CSS
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-block-end: 8px;
}

.chips button {
  flex: none;
}
Preview

On a narrow screen, the buttons don’t wrap to a new line, they scroll horizontally instead. flex: none keeps them from shrinking, and padding-block-end keeps the scrollbar clear of the buttons.

Definition and usage

#

The overflow-x property controls what happens to content that doesn’t fit an element’s width: it spills out, gets clipped, or becomes scrollable. Its twin, overflow-y, works the same way, just vertically. Both accept the same values as the overflow shorthand, which sets them at once.

Separate axes are useful when scrolling should only work in one direction. A horizontal filter bar on a phone, a wide table, or long lines of code get overflow-x: auto, while a sidebar or chat window that scrolls downward gets overflow-y: auto.

The axes aren’t fully independent though, and this rule catches almost everyone off guard. If one axis scrolls or clips with scrolling (hidden, scroll, auto), then visible on the other axis turns into auto, and clip turns into hidden. So you can’t scroll horizontally while still letting something overflow vertically. The exception is clip, which doesn’t force this swap.

Values other than visible and clip create a scroll container. That’s why overflow-x: hidden on an ancestor can break position: sticky. If you only want to clip the overflow, without scrolling, choose clip.

Syntax

#
Syntax
overflow-x: visible | hidden | clip | scroll | auto;
overflow-y: visible | hidden | clip | scroll | auto;

Values

#
  • visible

    The card strip overflows the frame on the right, and the badge above the first card overflows at the top. This is the default value.
  • hidden

    The overflow is clipped at the frame’s edge, with no scrollbar. Note that the badge is clipped too: the vertical axis switched from visible to auto.
  • auto

    A horizontal scrollbar appears only when the content doesn’t fit. The most common choice, but the badge still gets clipped.
  • scroll

    Room for a scrollbar is reserved always, even when the content fits. On systems that hide scrollbars (e.g. macOS), it looks like auto.
  • clip

    Clips the horizontal overflow without creating a scroll container. The vertical axis can stay visible, so the badge overflows in full.
  • overflow-y: auto

    vertical axis

    The same logic vertically. The list has a fixed height, and the overflow scrolls downward.

Values in practice

#

visible

The card strip overflows the frame on the right, and the badge above the first card overflows at the top. This is the default value.
.demo { overflow-x: visible; }

hidden

The overflow is clipped at the frame’s edge, with no scrollbar. Note that the badge is clipped too: the vertical axis switched from visible to auto.
.demo { overflow-x: hidden; }

auto

A horizontal scrollbar appears only when the content doesn’t fit. The most common choice, but the badge still gets clipped.
.demo { overflow-x: auto; }

scroll

Room for a scrollbar is reserved always, even when the content fits. On systems that hide scrollbars (e.g. macOS), it looks like auto.
.demo { overflow-x: scroll; }

clip

Clips the horizontal overflow without creating a scroll container. The vertical axis can stay visible, so the badge overflows in full.
.demo { overflow-x: clip; }

overflow-y: auto

The same logic vertically. The list has a fixed height, and the overflow scrolls downward.
.demo { overflow-y: auto; }

More examples

#
Long lines of code
CSS
pre {
  overflow-x: auto;
  padding: 12px 16px;
  border-radius: 10px;
  background: #18181b;
}
Preview

A code block doesn’t wrap its lines, so without overflow-x: auto a long line would stretch the page layout. With this declaration, only the block itself scrolls.

Browser support

#

Widely available

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

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • A card or filter strip on a phone is display: flex with overflow-x: auto on the parent and flex: none on the children.
  • A horizontal scrollbar on the whole page is better fixed at the source, by finding the element that’s too wide. If you must hide it, use overflow-x: clip instead of hidden, so you don’t break position: sticky.
  • Don’t try to combine scrolling on one axis with visible on the other. Move an overflowing menu or tooltip outside the scrolling element instead.

Related entries

#

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