CSS

CSS

🎯 CSS float Property

The float CSS property allows an element to move out of the normal document flow and align to the left or right side of its container.

It also allows surrounding content to wrap around the floated element, making it useful for layouts and image positioning.

🔹 Why Use float?

The float property is commonly used for creating layouts and wrapping text around images in web design.

  • Allows text wrapping around images
  • Helps create column-based layouts
  • Simple positioning method (legacy layouts)
  • Useful for basic UI structures

🧩 float Values

1️⃣ none (Default)

The element does not float and stays in the normal document flow.

CSS

div {
    float: none;
}
                

2️⃣ left

The element floats to the left, and content flows around its right side.

CSS

div {
    float: left;
}
                

3️⃣ right

The element floats to the right, and content flows around its left side.

CSS

div {
    float: right;
}
                

4️⃣ initial

Resets the property to its default value (none).

5️⃣ inherit

Inherits the float value from its parent element.

📌 Quick Summary

  • 🧠 Overview

  • none → element stays in normal flow
  • left → element floats left, text wraps right
  • right → element floats right, text wraps left
  • initial → resets to default value
  • inherit → takes value from parent element