overflow
Quick Summary for overflow
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.
Code Usage for overflow
/* Keyword values */ overflow: visible; overflow: hidden; overflow: clip; overflow: scroll; overflow: auto; overflow: hidden visible;  /* Global values */ overflow: inherit; overflow: initial; overflow: revert; overflow: unset; 
More Details for overflow

overflow

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.

Constituent properties

This property is a shorthand for the following CSS properties:

overflow-x overflow-y

Syntax

/* Keyword values */ overflow: visible; overflow: hidden; overflow: clip; overflow: scroll; overflow: auto; overflow: hidden visible;  /* Global values */ overflow: inherit; overflow: initial; overflow: revert; 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

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

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 overflow-x: scroll and overflow-y: hidden, or overflow: scroll hidden instead.

-moz-scrollbars-vertical

Use overflow-x: hidden and overflow-y: scroll, or overflow: hidden scroll instead.

-moz-hidden-unscrollable

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.

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

Formal definition

Initial valuevisible
Applies toBlock-containers, flex containers, and grid containers
Inheritedno
Computed valueas each of the properties of the shorthand:overflow-x: as specified, except with visible/clip computing to auto/hidden respectively if one of overflow-x or overflow-y is neither visible nor clipoverflow-y: as specified, except with visible/clip computing to auto/hidden respectively if one of overflow-x or overflow-y is neither visible nor clip
Animation typediscrete

Formal syntax

[ visible | hidden | clip | scroll | auto ]{1,2}

Examples

Setting different overflow values for text

HTML
  <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> 
CSS
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; } 
Result

Specifications

Specification
CSS Overflow Module Level 3 # propdef-overflow

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 Select your preferred language English (US)DeutschEspañolFrançais日本語한국어Português (do Brasil)Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote


seren spirit :(
Random CSS Property

color

The color CSS property sets the foreground color value of an element's text and text decorations, and sets the <currentcolor> value. currentcolor may be used as an indirect value on other properties and is the default for other color properties, such as border-color.
color css reference