CSS Reference ยท Box Model and Sizing
The overflow property
Reference for the CSS overflow property: visible, hidden, clip, scroll and auto, one or two values, effects on layout, examples and browser support.
The overflow property decides what happens when content is larger than its box: show it anyway, cut it off, or let the user scroll. It is a shorthand for overflow-x and overflow-y.
.panel { height: 8rem; overflow: auto; }
Try it
With visible the text spills out of its dashed box and may overlap what follows. hidden and clip cut it at the padding edge. scroll always shows scrollbars (where the platform draws them), and auto shows them only when needed.
Syntax
overflow: <overflow-x> <overflow-y>? /* each value: */ visible | hidden | clip | scroll | auto
One value applies to both axes. Two values are read as x then y.
- Initial value:
visible - Applies to: block containers, flex containers and grid containers
- Inherited: no
- Animatable: no
- Computed value: as specified, except that
visibleandclipcompute toautoandhiddenwhen the other axis is a different kind (see below)
Values
| Value | Description |
|---|---|
visible |
Content is not clipped and can render outside the box. |
hidden |
Content is clipped at the padding edge. The box is still a scroll container, so it can be scrolled by script or by focus, but the user gets no scrollbars. |
clip |
Content is clipped at the padding edge (or the overflow-clip-margin edge), and no scrolling of any kind is possible. The box is not a scroll container. |
scroll |
Content is clipped and scrollbars are always shown. |
auto |
Content is clipped and scrollbars appear only when the content overflows. |
Usage notes
- Mixed values.
visibleorclipon one axis and a scrolling value (hidden,scroll,auto) on the other cannot be combined:visiblebecomesautoandclipbecomeshidden. Onlyoverflow: clipon both axes, orvisibleon both, keeps the unclipped behavior. - Side effects of non-visible values.
hidden,scrollandautocreate a new block formatting context. That contains floats and stops margin collapsing through the box, but it also clips things like dropdowns, focus outlines and box shadows of children. position: stickybreaks. A sticky child sticks relative to its nearest scrolling ancestor. An ancestor withoverflow: hiddenorautocan make it appear to do nothing.overflow: clipavoids this, because the box is not a scroll container.- Always give a size. Scrolling needs a limited height or width. A box with
height: autosimply grows to fit its content. - Accessibility. Make scrollable regions keyboard reachable. Browsers focus scrollable areas with the keyboard in recent versions, but adding
tabindex="0"and an accessible name on key regions is safer. - Hiding the page scrollbar. Applying
overflow: hiddentobodyis a common way to lock page scroll behind a modal. - Smooth, contained scrolling. Pair it with
overscroll-behaviorandscroll-behavior.
Browser support
visible, hidden, scroll and auto work in every browser. The clip keyword and the two-value syntax are supported in all current major browsers (Baseline 2022 for clip).