CSS · Layout and visual systems

How do floats and clear work, and are they still used?

Mediumfloatclearlayout historyUpdated Oct 2026
Quiz this track

Short answer

A float takes an element out of normal block flow and lets inline content wrap around it. clear moves an element below preceding floats. Modern layouts use flex or grid instead.

Floats were originally for wrapping text around images. They are still useful for that, and for small editorial effects, but they are no longer the recommended way to build page layouts. Flexbox and grid handle distribution and alignment without clearing hacks.

css
.figure {
  float: right;
  width: 16rem;
  margin: 0 0 1rem 1rem;
}

.footer {
  clear: both;
}

.container {
  display: flow-root;
}

What to remember

  • Floated boxes are shifted to the left or right and inline content wraps around them
  • Floats remain in the flow as floats but are removed from normal block flow
  • A parent can collapse around floated children unless it establishes a block formatting context
  • clear: left, right or both prevents an element from sitting beside prior floats
  • display: flow-root contains floats without the old clearfix pseudo-element

The clearfix pattern was a workaround for containing floats. It still appears in older codebases, but flow-root is the modern declarative fix when a block formatting context is what you need.

Do not use floats for navigation bars, card grids or vertical centering. Those are layout problems that flex and grid solve with less coupling and fewer side effects.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What does clear actually do?
  2. 2Why can a parent collapse around floated children?
  3. 3What replaced the clearfix hack?
  4. 4When are floats still a reasonable choice?

Say it in the interview

Floats move a box to the left or right and let inline content wrap around it. They are out of normal block flow, so a parent can collapse around them unless it establishes a block formatting context. Clear moves an element below prior floats. I still use floats for wrapping text around images, but for layout I use flex or grid, and flow-root replaces clearfix.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live CSS mock interview and get scored feedback on depth, clarity and confidence.