English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Basic Tutorial

CSS Box Model

CSS3Basic Tutorial

CSS Reference Manual

CSS @rules

CSS Float (Float)

The CSS float property specifies whether the box should float. The float property in CSS is a positioning property. It is used to push an element to the left or right, allowing other elements to wrap around it, and is usually used for images and layouts.   

CSS Floating Elements

You can float an element to the left or right, but it only applies to elements that do not generateAbsolutely positionedThe elements in the box. Any element following the floated element will flow around it on the other side.

The float property may have one of the following three values:

ValueDescription
leftThe element floats to the left of its containing block.
rightThe element floats to the right of its containing block.
noneRemove the float property from the element.
initialIt sets the property to its initial value.
inheritIt is used to inherit this property from its parent element.

How Elements Float

The floated element will be moved out of the normal flow and moved as far left or right as possible within the available space of the containing element.

unless the float'sclearThis property prevents the flow of other elements, otherwise other elements would usually flow around the floated elements. The element floats horizontally, which means the element can only float to the left or right and cannot float up or down.

img {
    float: left;
}
Test to see‹/›

If multiple floated elements are placed adjacent to each other, they will float next to each other if there is horizontal space. If there is not enough space to contain the float, it will be moved down until it fits or there are no more floats.

.thumbnail {
    float: left;
    width: 125px;
    height: 125px;
    margin: 10px;
}
Test to see‹/›

Use (Clear) Clear Property to Close Floating

The elements following the floated elements will flow around them. The clear property specifies which side of the element box does not allow other floated elements to be placed.

.clear {
    clear: left;
}
Test to see‹/›

Note:This property can only clear elements from the same block-level floated boxes. It will not clear elements from the floated child boxes within the element itself. For more information on clearing floats, seeCSS AlignmentTutorial.