CSS overflow-x Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The overflow-x property controls what happens when content overflows a block-level element’s left and right edges. You can let it paint outside, clip it, or allow horizontal scrolling.

The initial value is visible. It is the horizontal half of the overflow shorthand; pair it with overflow-y when axes must differ. The box needs a limited width (or similar constraint) or nothing overflows horizontally.

Baseline · Widely available.

Not deprecated. Core keywords are standard-track. clip is widely available in modern browsers (Chrome 90+, Firefox 81+, Safari 16+). Deprecated / discouraged: overlay is a legacy alias for auto — do not use it in new code.

CSS Syntax

syntax.css
overflow-x: visible | hidden | clip | scroll | auto | initial | inherit;

Property Values

ValueDescriptionTry it
visibleDefault. Content may paint outside left and right edgesTry it
hiddenClips horizontal overflow. No scrollbar UITry it
clipClips horizontal overflow. Not a scroll container; no programmatic scrollTry it
scrollHorizontal scroll container; scrollbar track typically stays visibleTry it
autoHorizontal scrollbar appears only when content overflowsTry it
initialResets to the initial value, visibleTry it
inheritTakes the value from the parent elementTry it

How to Use overflow-x

Constrain width first, then choose how horizontal overflow should behave.

  1. Give the element a limited width or max-width.
  2. Put content inside that is wider than that limit (a long string or a wide child).
  3. Set overflow-x to auto, scroll, hidden, clip, or visible.
  4. Set overflow-y separately when vertical behavior must differ, or use the overflow shorthand for both axes.
PieceRequired?Role
Width constraintYes (to overflow)Without a limit, the box grows and nothing overflows
Wide contentYes (to observe)Long unbroken text or a wider child creates overflow
KeywordYesDecides paint outside, clip, or horizontal scroll
overflow-yOftenA non-visible overflow-y can change how visible computes

Live Preview

A narrow box holds one long line. Change overflow-x and watch how the extra width behaves.

Width stays fixed. Only the horizontal overflow keyword changes.

Box
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

overflow-x: auto

CSS Examples

Each snippet focuses on overflow-x. The fixed width is only there so content can overflow horizontally. Use Try It Yourself for a live editor.

Example 1 — Scroll When Needed

Show a horizontal scrollbar only if the line is wider than the box.

CSS
<style>
  div {
    width: 180px;
    overflow-x: auto;
    border: 1px solid #cbd5e1;
    padding: 8px;
    white-space: nowrap;
  }
</style>

<div>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</div>
Try It Yourself

How It Works

  1. Limit the width. width: 180px stops the box from growing with the text.
  2. Keep one long line. white-space: nowrap prevents wrapping so overflow is horizontal.
  3. Choose auto. overflow-x: auto clips the extra letters and adds a scrollbar only because it is needed.
  4. Scroll sideways. The clipped characters stay reachable with horizontal scroll.

Example 2 — Clip Without Scrollbars

Hide anything that sticks out on the left or right. No scrollbar appears.

CSS
<style>
  div {
    width: 180px;
    overflow-x: hidden;
    border: 1px solid #cbd5e1;
    padding: 8px;
    white-space: nowrap;
  }
</style>

<div>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</div>
Try It Yourself

How It Works

  1. Keep the same fixed width. Overflow still needs a constrained box.
  2. Switch to hidden. overflow-x: hidden clips content at the padding box on the sides.
  3. No scrollbar UI. Extra letters are cut off and not reachable by dragging a bar.
  4. Use for hard clips. Common for carousels, chips rows, and cards where extra width must stay out of sight.

Example 3 — Always Horizontally Scrollable

Force a horizontal scroll container so the scrollbar track stays available.

CSS
<style>
  div {
    width: 180px;
    overflow-x: scroll;
    border: 1px solid #cbd5e1;
    padding: 8px;
    white-space: nowrap;
  }
</style>

<div>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</div>
Try It Yourself

How It Works

  1. Set overflow-x to scroll. The element is always a horizontal scroll container.
  2. Clip at the padding box. Extra width stays inside the scrollable area.
  3. Expect scrollbar UI. Many browsers reserve horizontal scrollbar space even when content fits, which avoids layout jump.
  4. Prefer auto for most UI. Use scroll when you want the horizontal track to stay stable.

Edge Cases & Pitfalls

If horizontal overflow looks wrong, one of these is usually why.

width

No width limit, no overflow

Block boxes grow with content by default. Set a width or max-width before judging the keyword.

axes

visible can compute to auto

If overflow-y is hidden, scroll, or auto, a paired overflow-x: visible is computed as auto. Check both axes when results look unexpected.

wrap

Wrapping removes horizontal overflow

Normal text wraps at spaces. Use a long unbroken string, or white-space: nowrap, when you want to study horizontal overflow itself.

hidden

hidden is not the same as clip

Both clip horizontally. clip is not a scroll container and blocks programmatic scrolling. Prefer clip only when you want a hard non-scrolling clip.

overlay

overlay is discouraged

Treat overlay as a deprecated legacy alias of auto. Use auto in new CSS.

Browser Support

overflow-x is a browser CSS property for horizontal clipping and scrolling. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

overflow-x

Core values work in all modern browsers and Internet Explorer. overflow-x: clip needs Chrome 90+, Firefox 81+, Safari 16+, Edge 90+.

97% Core keyword support
Google Chrome All · clip 90+
Full support
Mozilla Firefox All · clip 81+
Full support
Apple Safari All · clip 16+
Full support
Microsoft Edge All · clip 90+
Full support
Opera Modern · clip 76+
Full support
Samsung Internet All · clip 15+
Full support
Internet Explorer 6+ · No clip
Partial
overflow-x Widely supported

Bottom line: Safe for visible, hidden, scroll, and auto everywhere you teach CSS. Use clip in modern browsers; fall back to hidden when needed. It is not a runtime API.

Key Takeaways

  • Role: control horizontal overflow on the left and right edges only.
  • Initial value: visible. Constrain width or nothing overflows.
  • auto vs scroll: auto when needed; scroll to keep a stable horizontal track.
  • Pair with overflow-y: a non-visible vertical value can change how visible computes.

One line: constrain width first, then pick a keyword — without a width limit, horizontal overflow never shows.

Frequently Asked Questions

It controls what happens when content is too wide for the element's padding box on the left and right edges: show it, clip it, or allow horizontal scrolling.
The initial value is visible. Content can paint outside the box horizontally, and the element is not a horizontal scroll container by itself.
overflow is the shorthand for both axes. overflow-x sets only the horizontal axis; overflow-y sets only the vertical axis.
scroll typically keeps a horizontal scrollbar track visible even when content fits. auto shows a horizontal scrollbar only when content actually overflows.
If overflow-y is hidden, scroll, or auto, a paired overflow-x: visible is computed as auto. Browsers do not keep one axis fully visible while the other is a scroll/clip mode.
Core values are Baseline Widely available across modern browsers and Internet Explorer. overflow-x: clip needs Chrome 90+, Firefox 81+, or Safari 16+. It is a browser CSS property, not a Node.js feature.

Next: overflow-y

Learn how to control overflow on the vertical axis.

overflow-y tutorial →

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.

8 people found this page helpful