CSS float Property Explained
What the CSS float property does, with an example.
Published November 7, 2026
float takes an element out of normal flow and pushes it left or right so text wraps around it. It was once used for layouts but is now mainly for wrapping text around images.
How it works
Floated elements collapse their parent's height unless you clear them. clearfix or display: flow-root fixes it.
Use flexbox or grid for layouts instead.
Values and effects
float: left; → float left
float: right; → float right
float: none; → normal
Practical examples
Image with wrapped text
img.avatar { float: left; margin: 0 1rem 1rem 0; }Contain floats
.wrap { display: flow-root; }Clear below
.footer { clear: both; }Common mistakes
- Using floats for page layout.
- Parent collapsing around floated children.
- Forgetting margins for text spacing.
Key takeaways
- float in one line: float takes an element out of normal flow and pushes it left or right so text wraps around it.
- Inspect it live in DevTools → Styles.
- Test across browsers and screen sizes.
FAQ
How do I clear floats?
Use display: flow-root on the parent or clear: both on the next element.
Is float supported in all browsers?
Yes in all modern browsers; check caniuse.com for edge cases.