Old School Layouts: The CSS Float Property

Discover how to wrap text around elements with the `float` property and learn the critical importance of `clear` to manage your layouts.

Lesson ProgressStep 1 of 8
Image

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam.

Footer Content
0 EXP

Welcome! Let's explore `float`, a legacy CSS property for layouts. Originally, it was for wrapping text around images.

.image {
  /* No float applied yet */
}

.text {
  /* Normal flow */
}

What is Float?

The `float` property in CSS was originally designed to allow text to wrap around images, just like you'd see in a newspaper or magazine.

When you apply `float` to an element, it is **taken out of the normal document flow**. This is the most critical concept to understand. The floated element is shifted as far as possible to the left or right within its parent container, and other inline content (like text) will "wrap" around it.

.my-image {
  float: left;
  margin: 0 15px 10px 0;
}

System Check

What was the original purpose of the `float` property?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🏆
Float Master

Correctly float an element and wrap text.

🏗️
Clearfix Whiz

Use the `clear` property to fix a collapsed container.

✍️
Legacy Architect

Build a multi-column layout using float.

Mission: Fix the Layout

Edit the CSS. Make the `.image` element float to the left, and ensure the `.footer` element appears *below* it by clearing the float.

A.D.A. Feedback:

> All checks passed, but the final layout isn't correct. Try again.

Challenge: Form the Rules

Drag the items to form two correct CSS rules: `float: left;` and `clear: both;`.

clear
float
both
left
;

Challenge: Complete the Syntax

Fill in the missing property names to fix this common layout problem.

.image {: left; }
.footer {: both; }

Consult A.D.A.

Community Holo-Net

Peer Project Review

Submit your "Legacy Layout" project for feedback from other Net-Runners.

Mastering CSS Floats: From Text Wrap to Legacy Layouts

When the web was young, developers needed a way to create complex layouts. Before Flexbox and Grid, the primary tool for this was the **`float`** property. Originally introduced in CSS 2.1 to allow text to wrap around images (like in a newspaper), clever developers realized it could be used to build entire multi-column page structures.

Today, using `float` for page layout is considered a **legacy technique**. Modern tools are far more powerful, predictable, and flexible. However, you will still encounter `float` in older codebases, and it's still the correct tool for its original purpose: wrapping text around an element.

The Core Properties: `float` and `clear`

The `float` property accepts a few values, but the two you'll use are:

  • float: left;: Takes the element out of the normal document flow and shifts it as far left as it can go in its container. Subsequent content will flow around its right side.
  • float: right;: Does the same, but shifts the element to the far right. Subsequent content flows around its left side.

Live Example:

placeholder

This text demonstrates the wrapping behavior. By applying `float: left` to the gray square, this paragraph text, which comes after it in the HTML, is forced to flow neatly around it. This is the primary and intended use case for the `float` property and is still perfectly valid today.

The Big Problem: The Collapsing Parent

The moment an element is floated, it is **removed from the normal document flow**. This means the parent container no longer "sees" its height. If a parent element contains *only* floated children, its height will collapse to zero, which can completely break your layout.

❌ The Problem

The red-dashed border shows the parent. Its height has collapsed.

.child-1
.child-2

✔️ The Solution

By "clearing" the floats, the parent now correctly contains them.

.child-1
.child-2

How to Fix It: Clearing Floats

To fix the collapsing parent, we must **clear** the floats. The `clear` property is applied to an element *after* the floats. It specifies that the element cannot be adjacent to a floated element.

  • clear: left;: Moves the element below any left-floated elements.
  • clear: right;: Moves the element below any right-floated elements.
  • clear: both;: Moves the element below **all** floated elements. This is what you will use 99% of the time.

Solution 1: The Clearfix Hack (Modern)

This is the most common and robust solution. You add a CSS pseudo-element (`::after`) to the *parent container* to clear the floats internally.

.parent-container::after {
  content: "";
  display: block;
  clear: both;
}

Solution 2: The Block Formatting Context (BFC) Method

This is a more "hacky" but very common solution you'll see. Applying certain CSS properties to the parent container (like overflow: auto; or overflow: hidden;) creates a new **Block Formatting Context (BFC)**. A BFC is a mini-layout environment that knows how to contain its own floats.

.parent-container {
  overflow: auto; /* or overflow: hidden */
}

This works perfectly but can have side effects (like hiding shadows or creating unwanted scrollbars if not careful).

Key Takeaway: **Do not use `float` for page layout in 2025.** Use Flexbox for one-dimensional layouts (rows or columns) and Grid for two-dimensional layouts (rows *and* columns). Use `float` only for its original purpose: wrapping text around images or other inline elements.

CSS Float & Layout Glossary

float
A CSS property that takes an element out of the normal document flow and positions it to the left or right of its container. Subsequent content (like text) will then wrap around it.
clear
A CSS property that specifies which sides of an element floating elements are not allowed to be adjacent to. It's used to control the behavior of elements *after* a floated element.
clear: both
The most common use of `clear`. It instructs an element to move down (clear) below any and all floated elements that appear before it in the HTML, whether they are floated left or right.
Normal Document Flow
The default layout behavior of HTML elements. Block-level elements stack vertically, one on top of the other, and inline-level elements flow horizontally. `float` removes an element from this flow.
Collapsing Parent
A common problem where a parent container's height collapses to zero because it contains only floated elements (which are outside the normal flow).
Clearfix Hack
A technique used to fix the "Collapsing Parent" problem. It typically involves adding an `::after` pseudo-element to the parent container, setting its `display` to `block`, and applying `clear: both`.
Block Formatting Context (BFC)
A mini, independent layout environment within a page. A key property of a BFC is that it will contain its own floats. Applying properties like `overflow: auto` (or `hidden`) to a parent is another way to fix the collapsing parent issue by creating a new BFC.
Legacy Layout
A layout method, like using `float` for multi-column structures, that is no longer the recommended best practice. Modern alternatives like Flexbox and Grid are preferred for their power and predictability.
Flexbox
A modern, one-dimensional CSS layout model that provides a more efficient way to arrange, align, and distribute space among items in a container, even when their size is unknown or dynamic.
Grid
A modern, two-dimensional CSS layout model designed for building complex page layouts with rows *and* columns. It is the most powerful layout system available in CSS.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching CSS and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest CSS specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!