CSS Overflow
You can give a box a fixed size. What if the content is taller or wider than that box? overflow decides whether the extra content spills out, gets clipped, or becomes scrollable.
Keywords at a glance
📊 Common overflow values
| Value | Everyday meaning |
|---|---|
visible (default) |
Extra content can spill outside the box |
hidden |
Extra content is clipped; no scrollbars |
scroll |
Scrollbars are shown (often even if not needed) |
auto |
Scrollbars appear only when content overflows |
Default: content can spill
With overflow: visible (the default), long content may paint outside the box edges.
Visible overflow (default)
css.box-visible {
width: 220px;
height: 80px;
overflow: visible;
border: 1px solid #94a3b8;
background-color: #f8fafc;
}
Clip with hidden
overflow: hidden cuts off anything that does not fit. Useful for clean edges — but users cannot scroll to the rest.
Hidden clips the spill
css.box-hidden {
width: 220px;
height: 80px;
overflow: hidden;
border: 1px solid #0f766e;
background-color: #ecfdf5;
}
Always show scrollbars with scroll
overflow: scroll makes the box scrollable and typically reserves scrollbar space even when content fits.
Scroll always
css.box-scroll {
width: 220px;
height: 80px;
overflow: scroll;
border: 1px solid #7c3aed;
background-color: #f5f3ff;
}
Auto — scroll only when needed
overflow: auto is a calm everyday choice for panels: scrollbars appear when content overflows, and often stay out of the way when it does not.
Auto when needed
css.box-auto {
width: 220px;
height: 80px;
overflow: auto;
border: 1px solid #b45309;
background-color: #fffbeb;
}
Control one axis
Use overflow-x and overflow-y when horizontal and vertical behavior should differ — for example, allow vertical scroll but clip sideways spill.
Vertical scroll, horizontal clip
css.panel-axes {
width: 240px;
height: 100px;
overflow-x: hidden;
overflow-y: auto;
border: 1px solid #334155;
background-color: #f1f5f9;
}
A practical panel habit
Give the box a real height (or max-height), then choose auto for readable, scrollable content areas.
Scrollable note panel
css.note-panel {
width: 100%;
max-height: 160px;
overflow: auto;
padding: 1rem;
border: 1px solid #cbd5e1;
background-color: #ffffff;
box-sizing: border-box;
}
Try it yourself
- Make a box with
widthand a shortheight, then paste several paragraphs inside. - Switch
overflowamongvisible,hidden,scroll, andauto. - Set
overflow-x: hiddenandoverflow-y: autoon a wide line of text. - Build
.note-panelwithmax-heightand watch scrollbars appear only when needed. - Notice that without a height (or max-height) limit, overflow often has nothing to constrain.
Common mistakes
- Expecting overflow effects without a constrained height or width
- Using
scrolleverywhere whenautowould feel calmer - Confusing overflow (box spill) with text-overflow (ellipsis on text — a later tool)
- Clipping with
hiddenand forgetting users may need a way to reach the rest - Assuming overflow changes box-sizing math (it does not)
Summary
- Overflow controls spill, clip, and scroll when content is larger than its box
- Default is
visible;hiddenclips;scrollalways offers bars;autowhen needed - A constrained size (height / max-height / width) is usually required to see the effect
overflow-xandoverflow-ysplit the axes- For many panels,
overflow: autois a calm habit
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top