Skip to: content, navigation

clear (CSS property)

Spec
Inherited Initial Version
No none CSS1
Browser support (more…)
IE5.5+ FF1+ Saf1.3+ Op9.2+
Buggy Full Full Full

Syntax

clear: { none | left | right | both | inherit } ;

Description

This property specifies which sides of an element’s box (or boxes) can’t be adjacent to any floated boxes. This property can clear an element only from floated boxes within the same block formatting context. It doesn’t clear the element from floated child boxes within the element itself.

The clearance is achieved by adding space above the top margin of the element, if necessary, until the top of the element’s border edge is below the bottom edge of any boxes floated in the specified direction or directions.

When clear is specified for a run-in box, it applies to the block box to which the run-in box eventually belongs.

See Floating and Clearing for more information about the behavior of cleared elements.

Example

This style rule prevents all pre elements in an HTML document from being adjacent to a previously floated box:

pre {
  clear: both;
}

Value

left

The value left adds space above the element’s generated box, if necessary, to put its top border edge below the bottom edge of any left-floating boxes previously generated by elements in the same block formatting context.

right

The value right adds space above the element’s generated box, if necessary, to put its top border edge below the bottom edge of any right-floating boxes previously generated by elements in the same block formatting context.

both

The value both adds space above the element’s generated box, if necessary, to put its top border edge below the bottom edge of any floating boxes that were previously generated by elements in the same block formatting context.

none

The value none doesn’t clear any previously floated boxes.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Buggy Buggy Buggy Full Full Full Full Full Full Full Full

Internet Explorer for Windows versions up to and including 6 exhibit a bug known as the peekaboo bug, wherein a cleared element that touches the floating box(es) it clears may become invisible.

Internet Explorer for Windows version 7:

  • doesn’t clear elements with an unshared ancestor whose height value is anything other than auto
  • doesn’t clear floated elements if the clear property is specified for an element floating in the opposite direction

Internet Explorer for Windows versions up to and including 7 don’t support the value inherit.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

Search