CSS overflow-x Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout & Scrolling

What You’ll Learn

The overflow-x property controls what happens when content is wider than its container. It is essential for horizontal scroll areas, wide tables, and responsive layouts.

01

Horizontal Overflow

Manage wide content.

02

Five Values

visible to clip.

03

Default visible

Show outside box.

04

Scrollbars

auto vs scroll.

05

Clip Content

Use hidden.

06

overflow-y

Vertical axis.

Introduction

The overflow-x property in CSS controls what happens to the content when it overflows the horizontal bounds of its container.

This property is particularly useful for managing horizontal scrolling and ensuring that overflowing content is handled gracefully.

It applies only to the horizontal axis, as opposed to the more general overflow property, which sets behavior for both axes at once.

Definition and Usage

Use overflow-x on elements with a defined width when content might exceed that width, such as data tables, code blocks, image carousels, and wide navigation strips.

overflow-x: auto is the most common choice because a horizontal scrollbar appears only when content actually overflows.

💡
Beginner Tip

Start with a 300px-wide container and 600px-wide content plus overflow-x: auto;. Scroll horizontally to see the effect.

📝 Syntax

The syntax for the overflow-x property is as follows:

syntax.css
element {
  overflow-x: value;
}

Here, value can be one of the predefined keywords described below.

Basic Example

overflow-x.css
.container {
  width: 300px;
  overflow-x: auto;
}

Syntax Rules

  • Accepted values: visible, hidden, scroll, auto, and clip.
  • The container usually needs a set width or max-width for horizontal overflow to matter.
  • overflow-x controls only the horizontal axis; pair it with overflow-y for vertical behavior.
  • auto is usually better than scroll when you want scrollbars only when needed.

🎯 Default Value

The default value of the overflow-x property is visible. This means that if the content overflows horizontally, it will not be clipped and will instead be visible beyond the bounds of its container.

Change it when you want to clip wide content or add horizontal scrolling inside a fixed-width box.

⚡ Quick Reference

QuestionAnswer
Initial valuevisible
Applies toBlock containers and flex/grid items
InheritedNo
AnimatableNo
Common useHorizontal scroll areas, wide tables, clipped wide content

💎 Property Values

ValueExampleDescription
visibleoverflow-x: visible;The content is not clipped, and it may overflow outside the content box.
hiddenoverflow-x: hidden;The content is clipped, and no scrollbars are provided to see the hidden content.
scrolloverflow-x: scroll;The content is clipped, but a horizontal scrollbar is added to allow the user to scroll to see the rest of the content.
autooverflow-x: auto;The browser decides whether to display a horizontal scrollbar. If the content fits, no scrollbar is shown; otherwise, a scrollbar appears.
clipoverflow-x: clip;Similar to hidden, but also disables scrollbars and prevents programmatic scrolling on the horizontal axis.
visible — default hidden — clip width scroll — always scroll auto — scroll when needed clip — hard clip

👀 Live Preview

Same wide content in narrow boxes with different overflow-x values (scroll inside the boxes):

auto
Wide horizontal content strip
hidden
Wide horizontal content strip
scroll
Wide horizontal content strip

Examples Gallery

Scroll wide content horizontally, clip overflow, compare scrollbar behavior, and build responsive data tables.

↔ Horizontal Scroll Areas

Use overflow-x: auto when content may exceed a fixed container width.

Example 1 — Container with overflow-x: auto

In this example, we’ll demonstrate the overflow-x property with a container that has more content than it can display horizontally.

overflow-x-auto.html
<style>
  .container {
    width: 300px;
    border: 1px solid #000;
    overflow-x: auto;
  }
  .content {
    width: 600px;
    background-color: lightblue;
  }
</style>

<div class="container">
  <div class="content">
    This is wide content that overflows the container. Adjust the overflow-x property to see the effect!
  </div>
</div>
Try It Yourself

How It Works

A horizontal scrollbar appears because the 600px content exceeds the 300px container width.

Example 2 — Clip Content with hidden

Hide horizontally overflowed content without showing scrollbars.

overflow-x-hidden.css
.strip {
  width: 280px;
  overflow-x: hidden;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
}
Try It Yourself

How It Works

Content beyond the right edge is cut off and cannot be scrolled into view.

🔄 Scroll & Tables

Compare always-on horizontal scrollbars and responsive table layouts.

Example 3 — Always Show Horizontal Scrollbars with scroll

Use overflow-x: scroll when you want horizontal scrollbar tracks present even if content fits.

overflow-x-scroll.css
.panel {
  width: 240px;
  overflow-x: scroll;
}
.panel-inner {
  width: 480px;
}
Try It Yourself

How It Works

Unlike auto, scroll reserves horizontal scrollbar space even when content does not overflow.

Example 4 — Horizontal Data Table Strip

Wrap a wide data table in a scrollable container so it stays usable on small screens.

table-strip.css
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
}
table {
  min-width: 640px;
  width: 100%;
  border-collapse: collapse;
}
Try It Yourself

How It Works

The wrapper scrolls horizontally while the table keeps its full column layout on narrow viewports.

overflow vs overflow-x vs overflow-y

The shorthand overflow sets both axes at once. Use overflow-x and overflow-y when horizontal and vertical behavior should differ.

overflow-companion.css
.code-block {
  overflow-x: auto;
  overflow-y: hidden;
}

♿ Accessibility

  • Do not hide important content — Using overflow-x: hidden can remove information from view with no way to scroll to it.
  • Ensure scrollable areas are usable — Keyboard users should be able to scroll focusable content inside horizontal overflow containers.
  • Prefer auto over scroll — when you want horizontal scrollbars only when content actually overflows.
  • Test small screens — Horizontal overflow behavior affects mobile layouts and table readability.

🧠 How overflow-x Works

1

Content exceeds container width

Wide text, images, tables, or child elements may extend past the box edge.

Content
2

overflow-x value is applied

The browser decides whether to show, clip, or scroll extra width horizontally.

Value
3

Layout stays controlled

Horizontal scrollbars or clipping keep the page design tidy and predictable.

Result
=

Managed horizontal overflow

Users can scroll sideways or see clipped content based on your choice.

Browser Compatibility

The overflow-x property is well-supported across modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It’s essential to test your designs in different browsers to ensure consistent behavior, especially when working with complex layouts or older browsers.

Baseline · Universal support

Excellent support everywhere

visible, hidden, scroll, and auto work reliably in all major browsers.

99% Global browser support
Google Chrome 1+ · All versions
Full support
Mozilla Firefox 1+ · All versions
Full support
Apple Safari 1+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 4+ · All versions
Full support
overflow-x property 99% supported

Bottom line: overflow-x is a dependable property for horizontal overflow in modern projects.

Conclusion

The overflow-x property is a valuable tool for controlling horizontal overflow behavior in web design.

By properly using this property, you can ensure that your content is presented in a user-friendly way, whether it involves hiding overflow, providing scrollbars, or other behaviors. Experiment with different values to find the best solution for your design needs.

💡 Best Practices

✅ Do

  • Use overflow-x: auto for wide tables and code blocks
  • Set width or max-width on overflow containers
  • Wrap wide tables in a scrollable div
  • Pair with overflow-y when axes need different behavior
  • Test horizontal overflow on mobile screen sizes

❌ Don’t

  • Hide important wide content with hidden without another way to access it
  • Use scroll everywhere when auto is enough
  • Expect overflow-x to work without width constraints on the box
  • Confuse overflow-x with overflow-wrap
  • Forget keyboard access inside horizontally scrollable regions

Key Takeaways

Knowledge Unlocked

Five things to remember about overflow-x

Use these points when content exceeds its container width.

5
Core concepts
02

Default visible

Show outside box.

Default
📝 03

Five Values

visible to clip.

Values
🔄 04

auto Scroll

Most common use.

Use case
05

overflow-y

Vertical axis.

Companion

❓ Frequently Asked Questions

overflow-x controls what happens when content overflows the horizontal bounds of its container, such as showing a horizontal scrollbar or clipping extra width.
The default value is visible, which means overflowing content is shown outside the container along the horizontal axis.
overflow is a shorthand that sets both horizontal and vertical overflow. overflow-x only affects the horizontal axis.
Use auto when you want a horizontal scrollbar only when content actually overflows. Use scroll when you always want horizontal scrollbar tracks visible.
No. overflow-x handles horizontal scrolling and clipping, while overflow-wrap breaks long words onto new lines to prevent overflow.

Practice in the Live Editor

Open the HTML editor and experiment with overflow-x: auto, hidden, and scroll on wide content.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful