Open In App

What is the use of the float Property in CSS ?

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The ‘float’ property in CSS is used to align elements horizontally within their container. It enables elements to be shifted to the left or right, allowing text and other elements to wrap around them. While originally designed for layout purposes, the ‘float’ property has been largely replaced by more modern layout techniques like Flexbox and Grid. Some uses are as:

Text Wrapping:

It allows text to wrap around elements, enhancing layout integration.

Syntax:

.float-left {
float: left;
}

Creating Layouts:

It is crucial for crafting multi-column structures and side-by-side element positioning.

Syntax:

.column {
float: left;
width: 50%;
}

Image Alignment:

It facilitates easy alignment of images within text, ensuring seamless integration.

.img-align-left {
float: left;
margin-right: 10px;
}

Clearing Elements:

It is used in conjunction with the clear property to prevent layout issues caused by floating elements.

Syntax:

.clearfix:after {
content: "";
display: table;
clear: both;
}

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads