</>
ValidateHTML

Using Floats for Layout

CSS float was designed for wrapping text around images, not for page layout. Using floats for layout requires clearfix hacks, causes parent collapse issues, and produces fragile layouts. Flexbox and Grid are the modern, purpose-built alternatives.

Why It Matters

Float-based layouts are fragile, hard to maintain, require clearfix workarounds, and break easily on different screen sizes. They represent outdated CSS practices from before Flexbox and Grid existed.

Code Examples

Bad CSS
.sidebar {
  float: left;
  width: 200px;
}

.content {
  float: left;
  width: calc(100% - 200px);
}

.clearfix::after {
  content: "";
  display: table;
  clear: both;
}
Good CSS
.layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
}

/* Or with Flexbox: */
.layout {
  display: flex;
  gap: 20px;
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
}

How to Fix

  • 1Replace float layouts with CSS Grid for two-dimensional layouts (rows + columns).
  • 2Use Flexbox for one-dimensional layouts (row OR column).
  • 3Float is still valid for its original purpose: wrapping text around images.
  • 4Flexbox and Grid have 98%+ browser support, there's no reason to use floats for layout.

Check Your CSS Now

Our CSS validator detects this error automatically and shows the exact line number.

Open CSS Validator
Recommended

Hostinger Fast & Affordable Web Hosting

Deploy clean, validated CSS on reliable hosting.

Get 80% Off Hosting →

Related CSS Errors

View all CSS errors