CSS Portal

CSS clear Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The clear property controls whether an element is allowed to sit beside preceding floated boxes or must be moved down below them. It is most often used to stop an element from wrapping alongside floats so that it begins on a new horizontal band in the flow of the document. By specifying which sides should be cleared, authors can force a block-level element to resume the normal flow below earlier floats rather than sharing the same inline space.

When an element with clearing behavior is laid out, the user agent examines the floats that precede it in the same block formatting context and shifts the element’s outer edge so it no longer overlaps those floats it is required to clear. This shifting does not change the document’s source order - it is purely a layout adjustment - and it does not itself create a new block formatting context. Because of that, clearing is frequently used in combination with other layout techniques; for example, using float to take content out of normal flow and then applying clearing to subsequent blocks to control where normal-flow content resumes. Also note that certain properties that establish a block formatting context can change how floats interact with surrounding content, so overflow is often considered when managing float containment.

In practice, developers use clearing to ensure parent containers expand around floated children or to prevent following content from flowing beside floats. Common patterns include inserting an element solely to clear preceding floats or using generated content with pseudo-elements as a “clearfix” so the parent contains its floated children. Because the effect concerns vertical placement relative to floats, it also interacts with spacing and layout decisions made with display and margins; combining clear with block-level display and appropriate margin settings gives predictable separation between floated regions and subsequent blocks.

There are a few edge cases to be aware of: absolutely positioned elements and elements removed from normal flow by other means are not affected by clearing in the same way as regular block-level boxes, so mixing clearing with positioning requires care. When designing layouts, consider how cleared elements will interact with stacking contexts and replaced elements that produce floats, and prefer clear-based techniques when you need a simple, reliable way to force an element below preceding floats rather than reworking the document structure. For fine-grained control alongside cleared placement, authors often combine clearing with positioning strategies such as position when absolute or fixed placement is also required.

Definition

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='container'>
<h2>CSS clear examples</h2>

<div class='float-box left'>Left float</div>
<div class='float-box right'>Right float</div>

<div class='clear both'>Cleared (both)</div>

<p>Following content shows how cleared elements affect flow.</p>

<div class='float-box left'>Left float 2</div>
<div class='clear left'>Cleared (left)</div>

<div class='float-box right'>Right float 2</div>
<div class='clear right'>Cleared (right)</div>

<div class='clear none'>No clear (none) - this sits beside floats if space allows</div>
</div>
/* Container */
.container {
  max-width: 760px;
  margin: 24px auto;
  padding: 16px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  line-height: 1.4;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #fff;
}

/* Floating boxes */
.float-box {
  width: 160px;
  padding: 12px;
  color: #fff;
  margin: 10px;
  box-sizing: border-box;
  border-radius: 4px;
}

.float-box.left {
  float: left;
  background: #2b8a78;
}

.float-box.right {
  float: right;
  background: #d9534f;
}

/* Clear utility classes */
.clear {
  display: block;
  padding: 8px 12px;
  margin: 12px 0;
  background: #f3f4f6;
  color: #333;
  border: 1px dashed #d1d5db;
  border-radius: 4px;
}

.clear.left { clear: left; }
.clear.right { clear: right; }
.clear.both { clear: both; }
.clear.none { clear: none; }

/* Small reset so the container grows past floats when needed */
.container::after {
  content: '';
  display: table;
  clear: both;
}

Browser Support

The following information will show you the current browser support for the CSS clear property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!