CSS Portal

CSS overflow-x Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The overflow-x property controls how content that extends beyond an element’s horizontal box is handled. At a basic level it determines whether that extra content is clipped, allowed to remain visible outside the element’s bounds, or made available via a horizontal scrolling mechanism; the property applies specifically to the x-axis, so it governs left/right overflow independently of vertical overflow. Because it targets only one axis, it’s commonly used when you need different horizontal and vertical behaviors for the same element (for example, allowing horizontal scrolling while keeping vertical overflow clipped).

Axis-specific behavior interacts with shorthand and counterpart properties: for example, overflow-y controls the vertical axis and the axis-specific properties normally take precedence over the shorthand overflow when both are present. This means you can set a general overflow behavior for an element and then fine-tune horizontal behavior independently. It’s important to remember this precedence when troubleshooting why content is or isn’t scrolling or being clipped.

The effect of overflow-x is also influenced by how the element participates in layout. Elements with intrinsic or auto sizing, their display type, and how children are sized or positioned will determine whether horizontal overflow actually occurs; this makes the interplay with properties such as display and white-space significant in practice. For instance, long unbroken text or preformatted blocks can create horizontal overflow unless the wrapping behavior is adjusted, and flex or grid containers handle child dimensions differently than block-level boxes.

In practical use, overflow-x is frequently applied to create horizontal scroll containers, to crop visual elements that should not extend past an edge, or to prevent unwanted horizontal scrollbars caused by wide children. It also affects painting and hit-testing: clipped content remains part of the DOM and accessible to assistive technologies even when visually hidden, but it will not be visible or interactive in the clipped region. Finally, because horizontal overflow can introduce scrollbars and change available inner space, designers should test for layout shifts and ensure a good experience on both pointer and touch devices; widths and heights of the container (e.g., width and height) and how content is sized will often be the deciding factors for whether horizontal overflow appears.

Definition

Initial value
visible
Applies to
Block containers, flex containers and grid containers
Inherited
No
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.overflowX

Interactive Demo

The value of Pi is 3.1415926535897932384626433832795029. The value of e is 2.7182818284590452353602874713526625.

Syntax

overflow-x: visible | hidden | scroll | auto

Values

  • visibleContent is not clipped and scroll bars are not added. Elements are clipped to the size of the containing window or frame.
  • hiddenContent that exceeds the dimensions of the object is not shown.
  • scrollContent is clipped and scroll bars are added, even if the content does not exceed the dimensions of the object.
  • autoContent is clipped and scrolling is added only when necessary.

Example

<div class="scroll-box">
<div class="wide-content">
This is a long piece of content that will force the container to scroll horizontally because it is much wider than its parent.
</div>
</div>
/* The container */
.scroll-box {
  width: 300px;
  height: 100px;
  border: 2px solid #333;
  
  /* This handles the horizontal overflow */
  overflow-x: auto;
  
  /* This prevents vertical scrollbars unless needed */
  overflow-y: hidden; 
}

/* The content inside */
.wide-content {
  width: 600px;
  height: 100%;
  background: linear-gradient(to right, #4facfe 0%, #00f2fe 100%);
  padding: 20px;
  color: white;
  white-space: nowrap;
}

Browser Support

The following information will show you the current browser support for the CSS overflow-x property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!