overflow

  • Revision slug: Web/CSS/overflow
  • Revision title: overflow
  • Revision id: 393781
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Moved From CSS/overflow to Web/CSS/overflow

Revision Content

{{ CSSRef() }}

Summary

The overflow CSS property specifies whether to clip content, render scroll bars or display overflow content of a block-level element.

Using the overflow property with a value different than visible, its default, will create a new block formatting context. This is technically necessary as if a float would intersect with the scrolling element it would force to rewrap the content of the scrollable element around intruding floats. The rewrap would happen after each scroll step and would be lead to a far too slow scrolling experience. Note that, by programmatically setting scrollTop to the relevant HTML element, even when overflow has the hidden value an element may need to scroll.

{{cssbox("overflow")}}

Syntax

Formal syntax: {{csssyntax("overflow")}}
overflow: visible
overflow: hidden
overflow: scroll
overflow: auto

overflow: inherit

Values

visible
Default value. Content is not clipped, it may be rendered outside the content box.
hidden
The content is clipped and no scrollbars are provided.
scroll
The content is clipped and desktop browsers use scrollbars, whether or not any content is clipped. This avoids any problem with scrollbars appearing and disappearing in a dynamic environment. Printers may print overflowing content.
auto
Depends on the user agent. Desktop browsers like Firefox provide scrollbars if content overflows.

Mozilla Extensions

-moz-scrollbars-none {{ obsolete_inline() }}
Use overflow:hidden instead.
-moz-scrollbars-horizontal {{ Deprecated_inline() }}
Use of {{ Cssxref("overflow-x") }} and {{ Cssxref("overflow-y") }} is preferred.
-moz-scrollbars-vertical {{ Deprecated_inline() }}
Use of {{ Cssxref("overflow-x") }} and {{ Cssxref("overflow-y") }} is preferred.
-moz-hidden-unscrollable {{ not_standard_inline() }}
Is intended mainly for internal use and by themes. Disables scrolling of XML root elements and <html>, <body> by arrow keys and mouse wheel.

Examples

p {  
     width: 12em;
     border: dotted;
     overflow: visible;   /* append scrollbars if necessary */ 
}

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
{{ SpecName('CSS3 Box', '#overflow1', 'overflow') }} {{ Spec2('CSS3 Box') }} No change.
{{ SpecName('CSS2.1', 'visufx.html#overflow', 'overflow') }} {{ Spec2('CSS2.1') }}  

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1") }} 4.0 7.0 1.0 (85)
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatGeckoMobile("1") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

Firefox (Gecko) Notes

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.

Internet Explorer Notes

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

See also

  • Related CSS properties: {{ cssxref("text-overflow") }}, {{ cssxref("white-space") }}, {{ Cssxref("overflow-x") }}, {{ Cssxref("overflow-y") }}, {{ Cssxref("clip") }}, {{ Cssxref("display") }}

Revision Source

<div>
  {{ CSSRef() }}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <code>overflow</code> CSS property specifies whether to clip content, render scroll bars or display overflow content of a block-level element.</p>
<p>Using the <code>overflow</code> property with a value different than <code>visible</code>, its default, will create a new <a href="/en-US/docs/CSS/block_formatting_context" title="CSS/block_formatting_context">block formatting context</a>. This is technically necessary as if a float would intersect with the scrolling element it would force to rewrap the content of the scrollable element around intruding floats. The rewrap would happen after each scroll step and would be lead to a far too slow scrolling experience. Note that, by programmatically setting <code>scrollTop</code> to the relevant HTML element, even when <code>overflow</code> has the <code>hidden</code> value an element may need to scroll.</p>
<p>{{cssbox("overflow")}}</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("overflow")}}</pre>
<pre>
overflow: visible
overflow: hidden
overflow: scroll
overflow: auto

overflow: inherit
</pre>
<h3 id="Values" name="Values">Values</h3>
<dl>
  <dt>
    <code>visible</code></dt>
  <dd>
    Default value. Content is not clipped, it may be rendered outside the content box.</dd>
  <dt>
    <code>hidden</code></dt>
  <dd>
    The content is clipped and no scrollbars are provided.</dd>
  <dt>
    <code>scroll</code></dt>
  <dd>
    The content is clipped and desktop browsers use scrollbars, whether or not any content is clipped. This avoids any problem with scrollbars appearing and disappearing in a dynamic environment. Printers may print overflowing content.</dd>
  <dt>
    <code>auto</code></dt>
  <dd>
    Depends on the user agent. Desktop browsers like Firefox provide scrollbars if content overflows.</dd>
</dl>
<h4 id="Mozilla_Extensions" name="Mozilla_Extensions">Mozilla Extensions</h4>
<dl>
  <dt>
    <code>-moz-scrollbars-none </code>{{ obsolete_inline() }}</dt>
  <dd>
    Use <code>overflow:hidden</code> instead.</dd>
  <dt>
    <code>-moz-scrollbars-horizontal </code>{{ Deprecated_inline() }}</dt>
  <dd>
    Use of {{ Cssxref("overflow-x") }} and {{ Cssxref("overflow-y") }} is preferred.</dd>
  <dt>
    <code>-moz-scrollbars-vertical </code>{{ Deprecated_inline() }}</dt>
  <dd>
    Use of {{ Cssxref("overflow-x") }} and {{ Cssxref("overflow-y") }} is preferred.</dd>
  <dt>
    -moz-hidden-unscrollable {{ not_standard_inline() }}</dt>
  <dd>
    Is intended mainly for internal use and by themes. Disables scrolling of XML root elements and <code>&lt;html&gt;</code>, <code> &lt;body&gt;</code> by arrow keys and mouse wheel.</dd>
</dl>
<h2 id="Examples" name="Examples">Examples</h2>
<pre class="brush: css">
p {  
     width: 12em;
     border: dotted;
     overflow: visible;   /* append scrollbars if necessary */ 
}
</pre>
<p style="overflow:visible;display:inline-block;width:12em;height:6em;border:dotted"><code>visible</code> (default)<br />
  Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.</p>
<pre>
p { overflow: hidden; /* no scrollbars are provided */ }
</pre>
<p style="overflow:hidden;display:inline-block;width:12em;height:6em;border:dotted"><code>overflow: hidden</code><br />
  Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.</p>
<pre>
p { overflow: scroll; /* always show scrollbars */ }
</pre>
<p style="overflow:scroll;display:inline-block;width:12em;height:6em;border:dotted"><code>overflow: scroll</code><br />
  Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.</p>
<pre>
p { overflow: auto; /* append scrollbars if necessary */ }
</pre>
<p style="overflow:auto;display:inline-block;width:12em;height:6em;border:dotted"><code>overflow: auto</code><br />
  Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.</p>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('CSS3 Box', '#overflow1', 'overflow') }}</td>
      <td>{{ Spec2('CSS3 Box') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS2.1', 'visufx.html#overflow', 'overflow') }}</td>
      <td>{{ Spec2('CSS2.1') }}</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{ CompatGeckoDesktop("1") }}</td>
        <td>4.0</td>
        <td>7.0</td>
        <td>1.0 (85)</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatGeckoMobile("1") }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatUnknown() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h3 id="Firefox_(Gecko)_Notes" name="Firefox_(Gecko)_Notes">Firefox (Gecko) Notes</h3>
<p>Through Firefox 3.6 (Gecko 1.9.2), the<code> overflow </code>property is incorrectly applied to table-group elements (<code>&lt;thead&gt;</code> , <code>&lt;tbody&gt;</code> , <code>&lt;tfoot&gt;</code>). This behavior is corrected in later versions.</p>
<h3 id="Internet_Explorer_Notes" name="Internet_Explorer_Notes">Internet Explorer Notes</h3>
<p>Internet Explorer 4 to 6 enlarges an element with<code> overflow:visible </code>(default value) to fit the content in it.<code> height/width </code>behaves like<code> min-height/min-width</code>.</p>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li>Related CSS properties: {{ cssxref("text-overflow") }}, {{ cssxref("white-space") }}, {{ Cssxref("overflow-x") }}, {{ Cssxref("overflow-y") }}, {{ Cssxref("clip") }}, {{ Cssxref("display") }}</li>
</ul>
Revert to this revision