clear

  • Revision slug: CSS/clear
  • Revision title: clear
  • Revision id: 20632
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment one or more formatting changes

Revision Content

{{ CSSRef() }}

Summary

The clear CSS property specifies whether an element can be next to floating elements that precede it or must be moved down (cleared) below them.

The clear property applies to both floating and non-floating elements.

When applied to non-floating blocks, it moves the border edge of the element down until it is below the margin edge of all relevant floats. This movement (when it happens) causes margin collapsing not to occur.

When applied to floating elements, it moves the margin edge of the element below the margin edge of all relevant floats. This affects the position of later floats, since later floats cannot be positioned higher than earlier ones.

The floats that are relevant to be cleared are the earlier floats within the same block formatting context.

Note: If you want an element to contain all floating elements inside it, you can either float the container as well, or use clear on a replaced {{ cssxref("::after") }} pseudo-element on it.

#container::after { 
   content: "";
   display: block; 
   visibility: hidden; 
   clear: both;
}
<style type="text/css"></style>
  • {{ Xref_cssinitial() }}: {{ Cssxref("none") }}
  • Applies to: block-level elements (including floats)
  • {{ Xref_cssinherited() }}: No
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

clear: none | left | right | both | inherit

Values

none
The element is not moved down to clear past floating elements.
left
The element is moved down to clear past left floats.
right
The element is moved down to clear past right floats.
both
The element is moved down to clear past both left and right floats.

Examples

{{ CSSRefExampleLink("clear") }}

h1 { clear: none }
h2 { clear: right }

Specifications

Specification Status Comment
CSS 2.1 {{ Spec2('CSS2.1') }} No significant changes, though details are precised.
CSS 1 {{ Spec2('CSS1') }}  

Browser compatibility

{{ CompatibilityTable() }}

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

See also

{{ languages( { "de": "de/CSS/clear", "fr": "fr/CSS/clear", "pl": "pl/CSS/clear" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h2 name="Summary">Summary</h2>
<p>The <code>clear</code> <a href="/en/CSS" title="CSS">CSS</a> property specifies whether an element can be next to <a href="/en/CSS/float" title="en/CSS/float">floating</a> elements that precede it or must be moved down (cleared) below them.</p>
<p>The <code>clear</code> property applies to both floating and non-floating elements.</p>
<p>When applied to non-floating blocks, it moves the <a href="/en/CSS/box_model" title="en/CSS/box_model">border edge</a> of the element down until it is below the <a href="/en/CSS/box_model" title="en/CSS/box_model">margin edge</a> of all relevant floats. This movement (when it happens) causes <a href="/en/CSS/margin_collapsing" title="en/CSS/margin_collapsing">margin collapsing</a> not to occur.</p>
<p>When applied to floating elements, it moves the <a href="/en/CSS/box_model" title="en/CSS/box_model">margin edge</a> of the element below the <a href="/en/CSS/box_model" title="en/CSS/box_model">margin edge</a> of all relevant floats. This affects the position of later floats, since later floats cannot be positioned higher than earlier ones.</p>
<p>The floats that are relevant to be cleared are the earlier floats within the same <a href="/en/CSS/block_formatting_context" title="en/CSS/block_formatting_context">block formatting context</a>.</p>
<div class="note"> <p><strong>Note: </strong>If you want an element to contain all floating elements inside it, you can either float the container as well, or use <code>clear</code> on a replaced {{ cssxref("::after") }} pseudo-element on it.</p> <pre>#container::after { 
   content: "";
   display: block; 
   visibility: hidden; 
   clear: both;
}
</pre>
</div>
<nobr>
<style type="text/css"><![CDATA[.cssprop {
  display:table;
  padding: 0.4em;
  border-left:0.15em solid;
  background-color:#eeeeff
}
.cssprop li {
 display:table-row;
 padding: 3px;
 margin:0;
}
.cssprop li dfn {
  display:table-cell;
  padding: 0 5px;
  border-bottom: none;
  cursor:inherit;
}

]]></style>
<ul class="cssprop"> <li><dfn>{{ Xref_cssinitial() }}:</dfn> {{ Cssxref("none") }}</li> <li><dfn>Applies to:</dfn> block-level elements (including floats)</li> <li><dfn>{{ Xref_cssinherited() }}:<dfn> No</dfn></dfn></li> <li><dfn>Media:</dfn> {{ Xref_cssvisual() }}</li> <li><dfn>{{ Xref_csscomputed() }}:</dfn> as specified</li>
</ul></nobr><h2 name="Syntax">Syntax</h2>
<pre class="eval syntaxbox">clear: none | left | right | both | <a href="/en/CSS/inherit" title="en/CSS/inherit">inherit</a>
</pre>
<h3 name="Values">Values</h3>
<dl> <dt><code>none</code></dt> <dd>The element is <em>not</em> moved down to clear past floating elements.</dd> <dt><code>left</code></dt> <dd>The element is moved down to clear past <em>left</em> floats.</dd> <dt><code>right</code></dt> <dd>The element is moved down to clear past <em>right</em> floats.</dd> <dt><code>both</code></dt> <dd>The element is moved down to clear past <em>both</em> left and right floats.</dd>
</dl>
<h3 name="Examples">Examples</h3>
<p>{{ CSSRefExampleLink("clear") }}</p>
<pre>h1 { clear: none }
h2 { clear: right }</pre>
<h2>Specifications</h2>
<table class="standard-table"> <thead> <tr style="background-color: rgb(255, 204, 255);"> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td><a class="external" href="http://www.w3.org/TR/CSS21/visuren.html#flow-control" title="http://www.w3.org/TR/CSS21/visuren.html#flow-control">CSS 2.1</a></td> <td>{{ Spec2('CSS2.1') }}</td> <td>No significant changes, though details are precised.</td> </tr> <tr> <td><a class="external" href="http://www.w3.org/TR/CSS1/#clear" title="http://www.w3.org/TR/CSS1/#clear">CSS 1</a></td> <td>{{ Spec2('CSS1') }}</td> <td> </td> </tr> </tbody>
</table>
<h2 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>3.5</td> <td>1.0</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>1.0</td> <td>{{ CompatGeckoMobile("1") }}</td> <td>6.0</td> <td>6.0</td> <td>1.0</td> </tr> </tbody> </table>
</div><h2 name="See_also">See also</h2>
<ul> <li>{{ Cssxref("float") }}</li> <li><a href="/en/CSS/box_model" title="en/CSS/box_model">Box model</a></li>
</ul>
<p>{{ languages( { "de": "de/CSS/clear", "fr": "fr/CSS/clear", "pl": "pl/CSS/clear" } ) }}</p>
Revert to this revision