The CSS float property is a positioning property. It is used to push an element to the left or right, allowing other element to wrap around it. It is generally used with images and layouts.
To understand its purpose and origin, let's take a look to its print display. In the print display, image is set into the page such that text wraps around it as needed.

Its web layout is also just similar to print layout.

The float property positions an element to the left or right of its containing element. After an element is floated, the surrounding inline content and other elements flow around it until the available horizontal space is occupied.
Some important points about the float property are:
| Property | Description | Values |
|---|---|---|
| clear | The clear property is used to avoid elements after the floating elements which flow around it. | left, right, both, none, inherit |
| float | It specifies whether the box should float or not. | left, right, none, inherit |
| Value | Description |
|---|---|
| none | It specifies that the element is not floated, and will be displayed just where it occurs in the text. this is a default value. |
| left | It is used to float the element to the left. |
| right | It is used to float the element to the right. |
| initial | It sets the property to its initial value. |
| inherit | It is used to inherit this property from its parent element. |
Let's see a simple example to understand the CSS float property.
The float: left value places an element on the left side of its container. The surrounding content flows around the right side of the floated element.
<!DOCTYPE html>
<html>
<head>
<style>
img {
float: left;
margin-right: 15px;
}
</style>
</head>
<body>
<img src="image.jpg" alt="Sample Image" width="120">
<p>
This paragraph wraps around the image because the image is floated to the left.
The text automatically occupies the remaining horizontal space beside the image.
</p>
</body>
</html>
Explanation
In this example:
When an element is floated, the following elements may also wrap around it. The clear property is used to prevent this behavior.
<!DOCTYPE html>
<html>
<head>
<style>
img {
float: left;
margin-right: 15px;
}
.clear {
clear: left;
}
</style>
</head>
<body>
<img src="image.jpg" alt="Sample Image" width="120">
<p>
This paragraph wraps around the image.
</p>
<p class="clear">
This paragraph starts below the floated image because of the clear property.
</p>
</body>
</html>
Explanation
The first paragraph flows beside the image. The second paragraph uses clear: left, so it is displayed below the floated image instead of wrapping around it.
The float property can also be used to create simple page layouts by placing elements beside each other.
<!DOCTYPE html>
<html>
<head>
<style>
.left {
float: left;
width: 50%;
background-color: lightblue;
}
.right {
float: right;
width: 50%;
background-color: lightgray;
}
</style>
</head>
<body>
<div class="left">
Left Column
</div>
<div class="right">
Right Column
</div>
</body>
</html>
Explanation
In this example:
We request you to subscribe our newsletter for upcoming updates.