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.
Fundamentals
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.
Foundation
📝 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.
Defaults
🎯 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.
The content is not clipped, and it may overflow outside the content box.
hidden
overflow-x: hidden;
The content is clipped, and no scrollbars are provided to see the hidden content.
scroll
overflow-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.
auto
overflow-x: auto;
The browser decides whether to display a horizontal scrollbar. If the content fits, no scrollbar is shown; otherwise, a scrollbar appears.
clip
overflow-x: clip;
Similar to hidden, but also disables scrollbars and prevents programmatic scrolling on the horizontal axis.
visible — defaulthidden — clip widthscroll — always scrollauto — scroll when neededclip — hard clip
Preview
👀 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
Hands-On
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><divclass="container"><divclass="content">
This is wide content that overflows the container. Adjust the overflow-x property to see the effect!
</div></div>
The wrapper scrolls horizontally while the table keeps its full column layout on narrow viewports.
Companion
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;}
A11y
♿ 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.
Compatibility
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 Chrome1+ · All versions
Full support
Mozilla Firefox1+ · All versions
Full support
Apple Safari1+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera4+ · All versions
Full support
overflow-x property99% supported
Bottom line:overflow-x is a dependable property for horizontal overflow in modern projects.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about overflow-x
Use these points when content exceeds its container width.
5
Core concepts
↔01
Horizontal Overflow
Manage wide content.
Purpose
⚙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.