float was historically used for page layout, but modern CSS prefers flexbox and grid for structure.
What float still does well
- Wrapping text around images.
- Legacy maintenance in older codebases.
Pitfall
Floated children can collapse parent height unless cleared (clearfix or modern alternatives).
Important interview questions and answers
- Q: Should you build new layouts with float?
A: Usually no; flexbox/grid are clearer and more robust. - Q: What is clearfix solving?
A: It makes parent contain floated children in normal flow. - Q: Practical modern use of float?
A: Text wrapping around media blocks.
Pitfall: Check cascade order—author stylesheet loses to inline styles and !important surprises.