1. css
  2. /properties
  3. /overflow-x

overflow-x

Definition

The "overflow-x" property is a CSS property that specifies how to handle content that overflows the horizontal width of an element's content area. It allows developers to control whether the browser should display a horizontal scroll bar, truncate the content, or clip the content.

Examples

Using "overflow-x" with the "visible" value. With this CSS, any content that overflows the horizontal width of the <div> element's content area will be visible, even if it extends beyond the boundaries of its container:

  div {
  overflow-x: visible;
}

Using "overflow-x" with the "hidden" value. With this CSS, any content that overflows the horizontal width of the <div> element's content area will be clipped and not visible to the user:

div {
  overflow-x: hidden;
}

Using "overflow-x" with the "scroll" value. With this CSS, a horizontal scroll bar will appear for the <div> element if any content overflows its content area, allowing the user to scroll horizontally to view the overflowed content.

  div {
  overflow-x: scroll;
}

Values

ValueDescription
visibleThe default value. The content that overflows the horizontal width of an element's content area is visible, even if it extends beyond the boundaries of its container.
hiddenThe content that overflows the horizontal width of an element's content area is clipped and not visible to the user.
scrollA horizontal scroll bar appears for the element if any content overflows its content area, allowing the user to scroll horizontally to view the overflowed content.

Best Practices

  • Use "overflow-x: hidden" to prevent horizontal overflow from extending beyond the boundaries of its container and interfering with other page elements.
  • Use "overflow-x: scroll" only when necessary, such as when the content is wider than the available screen space or the element's container is a fixed width.
  • Avoid using "overflow-x: visible" except when necessary, as it can cause horizontal overflow to extend beyond the element's container and interfere with other page elements.
  • Be mindful of the impact of "overflow-x" on the layout and readability of your content, especially in narrow or responsive containers.
  • Use a CSS preprocessor or utility class to apply "overflow-x" consistently across your project.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes