The overflow
CSS shorthand property sets the desired behavior for an element's overflow — i.e. when an element's content is too big to fit in its block formatting context — in both directions.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Constituent properties
This property is a shorthand for the following CSS properties:
Syntax
/* Keyword values */ overflow: visible; overflow: hidden; overflow: clip; 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.
Values
visible
- Content is not clipped and may be rendered outside the padding box.
hidden
- Content is clipped if necessary to fit the padding box. No scrollbars are provided, and no support for allowing the user to scroll (such as by dragging or using a scroll wheel) is allowed. The content can be scrolled programmatically (for example, by setting the value of a property such as
offsetLeft
), so the element is still a scroll container. clip
'- Like for
hidden
, the content is clipped to the element's padding box. The difference betweenclip
andhidden
is that theclip
keyword also forbids all scrolling, including programmatic scrolling. The box is not a scroll container, and does not start a new formatting context. If you wish to start a new formatting context, you can usedisplay: flow-root
to do so. scroll
- Content is clipped if necessary to fit the padding box. Browsers always display scrollbars whether or not any content is actually clipped, preventing scrollbars from appearing or disappearing as content changes. Printers may still print overflowing content.
auto
- Depends on the user agent. If content fits inside the padding box, it looks the same as
visible
, but still establishes a new block formatting context. Desktop browsers provide scrollbars if content overflows.
overlay
'- Behaves the same as
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.
Mozilla extensions
-moz-scrollbars-none
' [1]- Use
overflow: hidden
instead. -moz-scrollbars-horizontal
' [1]- Use
overflow-x
: scroll andoverflow-y
: hidden, oroverflow: hidden scroll
instead. -moz-scrollbars-vertical
' [1]- Use
overflow-x
: hidden andoverflow-y
: scroll, oroverflow: scroll hidden
instead. -moz-hidden-unscrollable
'- Use
overflow: clip
instead.
[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
Description
Overflow 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
.
Setting one axis to visible
(the default) while setting the other to a different value results in visible
behaving as auto
.
The JavaScript Element.scrollTop
property may be used to scroll an HTML element even when overflow
is set to hidden
.
Formal definition
Initial value | visible
|
Applies to | Block-containers, flex containers, and grid containers |
Inherited | no |
Computed value |
as each of the properties of the shorthand:
|
Animation type | discrete |
Formal syntax
[ visible | hidden | clip | scroll | auto ]{1,2}
Examples
Setting different overflow values for text
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 */ }
overflow: hidden
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
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.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Overflow Module Level 3The definition of 'overflow' in that specification. | Working Draft | Changed syntax to allow one or two keywords instead of only one |
CSS Level 2 (Revision 1)The definition of 'overflow' in that specification. | Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
overflow
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox Full support 1 Full support 1 Notes' After Firefox 3.6, the |
IE Full support 4 Full support 4 Notes' From version 4 to 6, Internet Explorer enlarges an element with |
Opera
Full support 7 |
Safari
Full support 1 |
WebView Android
Full support 37 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 14 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
|
Chrome
No support No |
Edge
No support No |
Firefox Full support 81 Full support 81 No support 1.5 — 81 Alternate Name' Uses the non-standard name: |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android Full support 81 Full support 81 No support 4 — 81 Alternate Name' Uses the non-standard name: |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
Multiple keyword syntax for overflow-x and overflow-y
|
Chrome
Full support 68 |
Edge
Full support 79 |
Firefox
Full support 61 |
IE
No support No |
Opera
Full support 55 |
Safari
No support No |
WebView Android
Full support 68 |
Chrome Android
Full support 68 |
Firefox Android
Full support 61 |
Opera Android
Full support 48 |
Safari iOS
No support No |
Samsung Internet Android
Full support 10.0 |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.'
- Experimental. Expect behavior to change in the future.
- See implementation notes.'
- See implementation notes.
- Uses a non-standard name.'
- Uses a non-standard name.
See also
- Related CSS properties:
text-overflow
,white-space
,overflow-x
,overflow-y
,overflow-inline
,overflow-block
,clip
,display
- CSS Overflow and Debug scrollable overflow
overflow by Mozilla Contributors is licensed under CC-BY-SA 2.5.