overflow

The overflow CSS property specifies whether to clip content, show scrollbars, or display overflowing content when it is too large for its block-level container.

/* 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 valuevisible
Applies tonon-replaced block-level elements and non-replaced inline-block elements
Inheritedno
Mediavisual
Computed valueas specified
Animation typediscrete
Canonical orderthe unique non-ambiguous order defined by the formal grammar

Syntax

The overflow property is specified as a single keyword chosen from the list of values below.

Values

visible
Content is not clipped and may be rendered outside the content box. Default value.
hidden
Content is clipped if necessary to fit the content box. No scrollbars are provided.
scroll
Content is clipped if necessary to fit the content box. Browsers display scrollbars whether or not any content is actually clipped. (This prevents scrollbars from appearing or disappearing when the content changes.) Printers may still print overflowing content.
auto
Depends on the user agent. If content fits inside the content box, it looks the same as visible, but still establishes a new block-formatting context. Desktop browsers like Firefox 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
Use overflow: hidden instead.
-moz-scrollbars-horizontal
Use of overflow-x and overflow-y is preferred.
-moz-scrollbars-vertical
Use of overflow-x and overflow-y is preferred.
-moz-hidden-unscrollable
Intended mainly for internal use and by themes. Disables scrolling of XML root elements, <html>, and <body> with the keyboard's arrow keys and the mouse wheel.

Formal syntax

visible | hidden | scroll | auto

Examples

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 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.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 (Yes) 1.0 (1.7 or earlier)[1] 4.0[2] 7.0 1.0 (85)
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ? (Yes) 1.0 (1)[1] ? ? ?

[1] Through Firefox 3.6 (Gecko 1.9.2), the overflow property is incorrectly applied to table-group elements (<thead> , <tbody> , <tfoot>). This behavior is corrected in later versions.

[2] Internet Explorer 4 to 6 enlarges an element with overflow: visible (default value) to fit the content inside it. height/width behaves like min-height/min-width.

See also