The overflow
CSS property sets what to do when an element's content is too big to fit in its block formatting context. It is a shorthand for overflow-x
and overflow-y
.
The options include clipping, showing scrollbars, or displaying the content flowing out of its container into the surrounding area.
Specifying 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: Setting one axis to visible
(the default) while setting the other to a different value results in visible
behaving as auto
.
Note: The JavaScript Element.scrollTop
property may be used to scroll an HTML element even when overflow
is set to hidden
.
/* Keyword values */ overflow: visible; overflow: hidden; overflow: scroll; overflow: auto; overflow: hidden visible; /* Global values */ overflow: inherit; overflow: initial; overflow: unset;
The overflow
property is specified as one or two keywords chosen from the list of values below. If two keywords are specified, the first applies to overflow-x
and the second to overflow-y
. Otherwise, both overflow-x
and overflow-y
are set to the same value.
visible
hidden
scroll
auto
visible
, but still establishes a new block-formatting context. Desktop browsers 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
[1]
overflow: hidden
instead.-moz-scrollbars-horizontal
[1]
overflow-x
: scroll
and overflow-y
: hidden
, or overflow: hidden scroll
instead.-moz-scrollbars-vertical
[1]
overflow-x
: hidden
and overflow-y
: scroll
, or overflow: scroll hidden
instead.-moz-hidden-unscrollable
<html>
, and <body>
with the keyboard's arrow keys and the mouse wheel.[1] As of Firefox 63, this feature is behind a feature preference setting. In about:config, set layout.css.overflow.moz-scrollbars.enabled
to true
[ visible | hidden | clip | scroll | auto ]{1,2}
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 | Changed syntax to allow one or two keywords instead of only one |
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. |
Initial value | visible |
---|---|
Applies to | Block-containers, flex containers, and grid containers |
Inherited | no |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 1 | 12 | 1
|
4
|
7 | 1 |
Multiple keyword syntax for overflow-x and overflow-y
|
68 | No | 61 | No | 55 | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | ? | ? | Yes | 4 | ? | ? | ? |
Multiple keyword syntax for overflow-x and overflow-y
|
68 | 68 | No | 61 | 55 | No | No |
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