CSS overflow Property

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

Definition and Usage

The overflow property is a shorthand for overflow-x and overflow-y. It controls what happens when content does not fit inside an element’s padding box.

The initial value is visible: content can paint outside the box. Other keywords clip the content, add scrollbars, or both. One keyword sets both axes; two keywords set horizontal then vertical. The box must be size-constrained (for example with height) or there is nothing to overflow.

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: visible | hidden | clip | scroll | auto | <overflow> <overflow> | initial | inherit;

One value sets both axes. Two values set overflow-x then overflow-y.

Property Values

ValueDescriptionTry it
visibleDefault. Content can paint outside the box. Not a scroll containerTry it
hiddenClips overflow. No scrollbars; may still scroll programmaticallyTry it
clipClips overflow. Not a scroll container; no programmatic scrollTry it
scrollAlways a scroll container; scrollbars typically stay visibleTry it
autoScrollbars appear only when content overflowsTry it
Two valuesFirst = horizontal (overflow-x), second = vertical (overflow-y)Try it
initialResets to the initial value, visibleTry it
inheritTakes the value from the parent elementTry it

How to Use overflow

Constrain the box first, then choose how overflow should behave.

  1. Give the element a limited size, usually with height, max-height, or width.
  2. Put content inside that is larger than that size.
  3. Set overflow to auto, scroll, hidden, clip, or visible.
  4. Use two values, or the overflow-x / overflow-y longhands, when axes must differ.
PieceRequired?Role
Size constraintYes (to overflow)Without a limit, the box grows and nothing overflows
Overflow keywordYesDecides clip, scroll, or paint outside
One or two valuesBy designSame on both axes, or horizontal then vertical
Keyboard accessFor scroll areasScrollable regions may need focusability for keyboard users

Live Preview

A short fixed box holds long text. Change overflow and watch how the extra lines behave.

Width and height stay fixed. Only the overflow keyword changes.

Box
Overflow happens when content is taller than this box. Try each keyword and compare how the extra text is shown, clipped, or scrolled.

overflow: auto

CSS Examples

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

Example 1 — Scroll When Needed

Show a scrollbar only if the text does not fit.

CSS
<style>
  div {
    width: 200px;
    height: 80px;
    overflow: auto;
    border: 1px solid #cbd5e1;
    padding: 8px;
  }
</style>

<div>
  This box is short. Extra lines overflow, so auto adds a scrollbar when needed.
</div>
Try It Yourself

How It Works

  1. Limit the box. width and height stop the container from growing with the text.
  2. Put in more content. The paragraph is taller than 80px, so it overflows.
  3. Choose auto. overflow: auto clips the extra text and shows a scrollbar only because it is needed.
  4. Scroll to read. The box becomes a scroll container so the clipped lines stay reachable.

Example 2 — Clip Without Scrollbars

Hide anything that does not fit. No scrollbar appears.

CSS
<style>
  div {
    width: 200px;
    height: 80px;
    overflow: hidden;
    border: 1px solid #cbd5e1;
    padding: 8px;
  }
</style>

<div>
  Extra text is clipped at the edge of this box. There is no scrollbar.
</div>
Try It Yourself

How It Works

  1. Keep the same fixed size. Overflow still needs a constrained box.
  2. Switch to hidden. overflow: hidden clips content at the padding box.
  3. No scrollbar UI. Users cannot drag a bar to see the rest, though browsers may still allow programmatic scroll.
  4. Use for hard clips. Common for cards, image crops, and menus where extra content must stay out of sight.

Example 3 — Always Scrollable

Force a scroll container so scrollbars stay available.

CSS
<style>
  div {
    width: 200px;
    height: 80px;
    overflow: scroll;
    border: 1px solid #cbd5e1;
    padding: 8px;
  }
</style>

<div>
  This box always acts as a scroll container. Scrollbars typically stay visible.
</div>
Try It Yourself

How It Works

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

Edge Cases & Pitfalls

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

size

No size limit, no overflow

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

hidden

hidden is not the same as clip

hidden can still create a scroll container and allow programmatic or keyboard scroll into view. clip does not. Prefer clip only when you want a hard non-scrolling clip.

axes

Mixed axes change visible / clip

If one axis is neither visible nor clip, a paired visible computes like auto, and a paired clip can compute like hidden. Check both axes when results look unexpected.

a11y

Make scroll areas keyboard-reachable

Some browsers do not focus scrollable boxes by default. For important scroll regions, consider tabindex="0", a landmark role, and an accessible name.

overlay

overlay is discouraged

Treat overlay as a deprecated legacy alias of auto. Use auto (and modern scrollbar properties such as scrollbar-gutter when you need gutter control).

Browser Support

overflow is a browser CSS property for clipping and scroll containers. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

overflow

Core values work in all modern browsers and Internet Explorer. overflow: 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 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: shorthand for how overflowing content is shown, clipped, or scrolled on both axes.
  • Initial value: visible. Constrain the box or nothing overflows.
  • auto vs scroll: auto when needed; scroll to keep a stable scroll container UI.
  • hidden vs clip: both clip; only clip blocks programmatic scrolling as a non-scroll container.

One line: constrain the box first, then pick a keyword — without a size limit, overflow never shows.

Frequently Asked Questions

It is a shorthand for overflow-x and overflow-y. It controls what happens when content is too large for the element's padding box: show it, clip it, or make the box scrollable.
The initial value is visible. Overflowing content can paint outside the box, and the element is not a scroll container.
scroll always makes a scroll container and typically shows scrollbars even when content fits. auto adds scrollbars only when content actually overflows.
Both clip overflowing content. hidden can still create a scroll container and allow programmatic or keyboard scrolling into view. clip does not create a scroll container and blocks programmatic scrolling.
The box must be constrained. Without a height, max-height, width, or similar limit, block boxes grow with their content and nothing overflows.
Core values are Baseline Widely available across modern browsers and Internet Explorer. overflow: clip needs Chrome 90+, Firefox 81+, or Safari 16+. It is a browser CSS property, not a Node.js feature.

Next: overflow-anchor

Learn how browsers stabilize scroll position when content shifts.

overflow-anchor 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