CSS overflow
Run
Stack editor
Unstack editor
Examplediv {
width: 50vw;
height: 50vh;
border: 1vw solid orange;
font-size: 5vw;
padding: 5vw;
margin: auto;
overflow: auto;
}
The CSS overflow property allows you to determine what to when a box is too small for its contents. You can create scroll bars, hide the contents, or automatically expand the box.
As of CSS3, the overflow property is a shorthand property for the overflow-x and overflow-y properties (those properties were only introduced in CSS3). The overflow property allows you to set both of those properties at once.
Syntax
overflow: visible | hidden | scroll | auto
Three additional keywords have also been proposed: no-content, no-display, and clip, however, see the note below for information on these values.
Possible Values
The overflow property is shorthand, and accepts one or two keywords (below). If it has one keyword, that keyword sets both overflow-x and overflow-y; if it has two keywords, it sets overflow-x to the first and overflow-y to the second
visible
Specifies that the content should not be clipped. In other words, it should be displayed outside the content box.
hidden
Specifies that the content is clipped (i.e. the parts that extend beyond the content box are hidden), and no scroll bars (or other scrolling mechanism) are supplied.
scroll
Specifies that the content box should provide scroll bars (or other scrolling mechanism) regardless of whether the content is clipped or not.
auto
Specifies that the content box should provide scroll bars (or other scrolling mechanism) only when the content overflows (i.e. is too big to fit within the content box).
In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:
initial
Represents the value specified as the property's initial value.
inherit
Represents the computed value of the property on the element's parent.
unset
This value acts as either inherit or initial, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.
New Values
The CSS basic box model adds two keywords to the overflow properties:
no-display
When the content doesn't fit in the content box, the whole box is removed, as if display: none were specified.
no-content
When the content doesn't fit in the content box, the whole content is hidden, as if visibility: hidden were specified.
The CSS Overflow Module Level 3 adds only one keyword, defined as follows:
clip
Like hidden, this value indicates that the box's content is clipped to its padding box and that no scrolling user interface should be provided by the UA to view the content outside the clipping region. In addition, unlike overflow: hidden which still allows programmatic scrolling, overflow: clip forbids scrolling entirely, through any mechanism, and therefore the box is not a scroll container.
However these two specifications are still in draft status and these values are experimental so avoid using them until they become more stable and gain better browser support.
General Information
Initial Value
See individual properties
Applies To
The exact wording depends on the spec:
CSS2: Block containers.
CSS basic box model: Non-replaced block-level elements and non-replaced 'inline-block' elements.
CSS Overflow Module Level 3: Block containers, flex containers, and grid containers.
Inherited?
No
Media
Visual
Example Code
.small-box {
overflow: scroll;
}
Official Specifications
CSS Overflow Module Level 3 (W3C Working Draft, 31 May 2016)
CSS basic box model (W3C Working Draft 9 August 2007)
CSS Level 2.1 (W3C Recommendation 07 June 2011)