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 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.
This property is a shorthand for the following CSS properties:
/* Keyword values */ overflow: visible; overflow: hidden; overflow: clip; overflow: scroll; overflow: auto; overflow: hidden visible; /* Global values */ overflow: inherit; overflow: initial; overflow: revert; overflow: revert-layer; 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
Content is not clipped and may be rendered outside the padding box.
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 scrollLeft
or the scrollTo()
method), so the element is still a scroll container.
clip
Similar to hidden
, the content is clipped to the element's padding box. The difference between clip
and hidden
is that the clip
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 use display: 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
Deprecated
Behaves the same as auto
, but with the scrollbars drawn on top of content instead of taking up space.
-moz-scrollbars-none
Deprecated
Use overflow: hidden
instead.
-moz-scrollbars-horizontal
Deprecated
Use
and overflow-x
: scroll
, or overflow-y
: hiddenoverflow: scroll hidden
instead.
-moz-scrollbars-vertical
Deprecated
Use
and overflow-x
: hidden
, or overflow-y
: scrolloverflow: hidden scroll
instead.
Use overflow: clip
instead.
As of Firefox 63, -moz-scrollbars-none
, -moz-scrollbars-horizontal
, and -moz-scrollbars-vertical
are behind a feature preference setting. In about:config, set layout.css.overflow.moz-scrollbars.enabled
to true
.
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) or clip
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
.
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 |
<div> <code>visible</code> <p class="visible"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. </p> </div> <div> <code>hidden</code> <p class="hidden"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. </p> </div> <div> <code>scroll</code> <p class="scroll"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. </p> </div> <div> <code>auto</code> <p class="auto"> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. </p> </div>
body { display: flex; justify-content: space-around; } div { margin: 1em; font-size: 1.2em; } p { width: 8em; height: 5em; border: dotted; } p.visible { overflow: visible; } p.hidden { overflow: hidden; } p.scroll { overflow: scroll; } p.auto { overflow: auto; }
Specification |
---|
CSS Overflow Module Level 3 # propdef-overflow |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
overflow |
1 |
12 |
1
After Firefox 3.6, the
overflow property is correctly applied to table group elements (<thead> , <tbody> , <tfoot> ). |
4
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. |
7 |
1 |
37 |
18 |
4 |
14 |
1 |
1.0 |
clip |
90 |
90 |
81
1.5-81
|
No |
76 |
16 |
90 |
90 |
81
4-81
|
No |
16 |
15.0 |
multiple_keywords |
68 |
79 |
61 |
No |
55 |
No |
68 |
68 |
61 |
48 |
No |
10.0 |
overlay |
15 |
79 |
No |
No |
15 |
No |
100 |
100 |
No |
No |
No |
4.0 |
text-overflow
, white-space
, overflow-x
, overflow-y
, overflow-inline
, overflow-block
, clip
, display
© 2005–2022 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow