CSS clear Property

Description

The clear CSS property is used to control the behavior of an element in relation to nearby floated elements. When an element is set to clear, it specifies whether it should be allowed to float next to any preceding floated elements, or if it should be moved below them, effectively clearing the floated content. This property is particularly useful for maintaining the layout and positioning of elements within a webpage, ensuring that elements do not overlap or interfere with floated elements that appear earlier in the HTML structure. The clear property can take values like left, right, both, or none, which dictate the clearing behavior in different directions, and it is commonly used in conjunction with floated elements to achieve desired layout outcomes.

Initial value
auto
Applies to
Block-level elements
Inherited
No
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.clear

Interactive Demo

Left
Right
The rusty swing set creaked a lonely lullaby in the twilight, shadows lengthening like grasping fingers across the dew-kissed grass. A lone dandelion seed, adrift on the breeze, whispered secrets of faraway fields, of dandelion suns and galaxies spun from fluff. Somewhere, beyond the veil of dusk, a coyote laughed, echoing through the stillness like a forgotten memory.

Syntax

clear: none | left | right | both

Values

  • noneThe element is not moved down to clear past floating elements.
  • leftThe element is moved down to clear past left floats.
  • rightThe element is moved down to clear past right floats.
  • bothThe element is moved down to clear past both left and right floats.

Example

<div class="pull-left">
<img src="images/2.png" alt="">
</div>
<div class="clearfix"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
.pull-left { 
   float: left; 
   padding-right: 10px; 
} 
.clearfix {
   clear: both; 
} 

Browser Support

The following table will show you the current browser support for the CSS clear property.

Desktop
Edge Chrome Firefox Opera Safari
12113.51
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
18410.1114.4

Last updated by CSSPortal on: 1st January 2024