CSS overflow-x Property

Description

The overflow-x CSS property is used to control how content overflows in the horizontal direction within an HTML element with a specified width and height. It determines whether a horizontal scrollbar should appear when the content overflows the element's designated width. The property can take several values, including "visible" (default, where content overflows the element), "hidden" (content is clipped and no scrollbar appears), "scroll" (a scrollbar is always visible), and "auto" (a scrollbar appears only when content exceeds the element's width). overflow-x is particularly useful for managing horizontal overflow situations, such as long text strings or wide images within containers.

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="test"> visible
<img src="images/tech.gif" alt="">
</div>
<div class="test2"> hidden
<img src="images/tech.gif" alt="">
</div>
<div class="test3"> scroll
<img src="images/tech.gif" alt="">
</div>
<div class="test4"> auto
<img src="images/tech.gif" alt="">
</div>
div {
   display: inline-block; 
   margin-right: 30px;
   width: 100px; 
   height: 100px;
   border: 2px solid blue; 
}
img {
   width: 125px;
   height: 125px;
}
.test {
   overflow-x: visible;
   overflow-y: visible;
}
.test2 {
   overflow-x: hidden;
   overflow-y: hidden; 
}
.test3 {
   overflow-x: scroll;
   overflow-y: scroll;
}
.test4 {
   overflow-x: auto;
   overflow-y: auto; 
}

Browser Support

The following table will show you the current browser support for the CSS overflow-x property.

Desktop
Edge Chrome Firefox Opera Safari
1213.59.53
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
184141137

Last updated by CSSPortal on: 2nd January 2024