The overflow
CSS property is shorthand for the overflow-x
and overflow-y
properties, and specifies what to do when content is too large to fit in its block formatting context.
The options include clipping, showing scrollbars, or displaying the content flowing out of its container into the surrounding area.
/* Content is not clipped */ overflow: visible; /* Content is clipped, with no scrollbars */ overflow: hidden; /* Content is clipped, with scrollbars */ overflow: scroll; /* Let the browser decide */ overflow: auto; /* Global values */ overflow: inherit; overflow: initial; overflow: unset;
Using overflow
with a value other than visible
(the default) creates a new block formatting context. This is necessary for technical reasons — if a float intersected with the scrolling element it would forcibly rewrap the content after each scroll step, leading to a slow scrolling experience.
In order for overflow
to have an effect, the block-level container must have either a set height (height
or max-height
) or white-space
set to nowrap
.
Note: The JavaScript Element.scrollTop
property may be used to scroll an HTML element even when overflow
is set to hidden
.
Initial value | visible |
---|---|
Applies to | non-replaced block-level elements and non-replaced inline-block elements |
Inherited | no |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
The overflow
property is specified as a single keyword chosen from the list of values below.
visible
hidden
scroll
auto
visible
, but still establishes a new block-formatting context. Desktop browsers like Firefox provide scrollbars if content overflows.overlay
auto
, but with the scrollbars drawn on top of content instead of taking up space. Only supported in WebKit-based (e.g., Safari) and Blink-based (e.g., Chrome or Opera) browsers.-moz-scrollbars-none
overflow: hidden
instead.-moz-scrollbars-horizontal
overflow-x
and overflow-y
is preferred.-moz-scrollbars-vertical
overflow-x
and overflow-y
is preferred.-moz-hidden-unscrollable
<html>
, and <body>
with the keyboard's arrow keys and the mouse wheel.visible | hidden | scroll | auto
p { width: 12em; height: 6em; border: dotted; overflow: visible; /* content is not clipped */ }
visible
(default)
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
p { overflow: hidden; /* no scrollbars are provided */ }
p { overflow: scroll; /* always show scrollbars */ }
overflow: scroll
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
p { overflow: auto; /* append scrollbars if necessary */ }
overflow: auto
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
Specification | Status | Comment |
---|---|---|
CSS Overflow Module Level 3 The definition of 'overflow' in that specification. | Working Draft | |
CSS Basic Box Model The definition of 'overflow' in that specification. | Working Draft | No change. |
CSS Level 2 (Revision 1) The definition of 'overflow' in that specification. | Recommendation | Initial definition. |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1 | Yes | 11 | 42 | 7 | 1 |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|---|---|
Basic support | ? | ? | Yes | 4 | ? | ? | ? |
1. After Firefox 3.6, the overflow
property is correctly applied to table group elements (<thead>
, <tbody>
, <tfoot>
).
2. From version 4 to 6, Internet Explorer enlarges an element with overflow: visible
(default value) to fit the content inside it. height
and width
behave like min-height
and min-width
, respectively.
text-overflow
, white-space
, overflow-x
, overflow-y
, clip
, display
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow