Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. clear

clear

Clears the wrapping around floated elements (floating elements) that exist before it. This property is used for layout control when float is in use. See the float page first.

Sample Code

style.css
/* no clearing (initial value) */
.item { clear: none;}

/* clear wrapping caused by left-floated elements */
.after-left-float { clear: left;}

/* clear wrapping caused by right-floated elements */
.after-right-float { clear: right;}

/* clear wrapping caused by both left and right floats */
.clearfix-item { clear: both;}

/* common pattern: footer clears floated sidebar and main content */
.sidebar { float: left; width: 30%;}
.main-content { float: right; width: 65%;}
.footer { clear: both;} /* footer is placed below both sidebar and main content */

Available Values

ValueDescription
noneDoes not clear the wrapping around floating elements that exist before it. This 'none' is the initial value.
bothClears all wrapping around floating elements that exist before it.
leftClears the wrapping around floating elements before it whose 'float' property is set to 'left'.
rightClears the wrapping around floating elements before it whose 'float' property is set to 'right'.

Browser Preview

<div style="float: left; width: 200px; background-color: #ff0;">This is a div element with 'float: left' and 'width: 200px'.</div>
<p style="clear: left;">This is a p element. 'clear: left' is specified to clear the wrapping from the preceding floating element.</p>

<div style="float: right; width: 200px; background-color: #ff0;">This is a div element with 'float: right' and 'width: 200px'.</div>
<p style="clear: right;">This is a p element. 'clear: right' is specified to clear the wrapping from the preceding floating element.</p>

<div style="float: left; width: 200px; background-color: #ff0;">This is a div element with 'float: left' and 'width: 200px'.</div>
<p style="clear: both;">This is a p element. 'clear: both' is specified to clear the wrapping from the preceding floating element.</p>

Browser Support

Chrome Chrome
1+
Firefox Firefox
1+
Safari Safari
1+
Edge Edge
12+
IE IE
11
10
9
8
7
6
Opera Opera
3.5+
2 and earlier ×
iOS Safari iOS Safari
1+
Android Android Browser
4.4+
3 and earlier ×
Chrome Android Chrome Android
Latest
Same support as desktop
Firefox Android Firefox Android
Latest
Same support as desktop

※ Version data based on MDN.

Overview

Clears the wrapping around floated elements (floating elements) that exist before it.

Strictly speaking, it does not simply clear the wrapping around preceding floating elements — it automatically generates upward margin equal to the height of the preceding floating element. This automatically generated upward margin is called 'clearance'. Note that if both the 'clear' property and the 'margin-top' property are specified simultaneously, the 'clearance' generated by the 'clear' property takes precedence.

<div style="float: left; width: 200px; background-color: #ff0;">This is a div element with 'float: left' and 'width: 200px'.</div>
<p style="clear: both; margin-top: 1000px;">This is a p element with 'clear: both' and 'margin-top: 1000px'. Because 'clearance' takes precedence, the top margin will not become '1000px'.</p>

If you find any errors or copyright issues, please .