What is Float?
The float property is used to position elements to the left or right, allowing text and inline elements to wrap around them.
Basic Float
CSSRead-only
1
Float Values
| Value | Description |
|---|---|
| left | Float element to left |
| right | Float element to right |
| none | Default (no float) |
Text Wrapping Example
CSSRead-only
1
Clear Property
The clear property specifies which sides of floating elements are not allowed to float.
CSSRead-only
1
Clear Values
| Value | Description |
|---|---|
| left | Clears left floats |
| right | Clears right floats |
| both | Clears both sides |
| none | Default |
Float Layout Example
CSSRead-only
1
Clearing Float (Fix Layout)
CSSRead-only
1
Modern Alternative
Float is mostly replaced by Flexbox and Grid for layout design.
Best Practices
- Use float mainly for text wrapping
- Use clear to avoid layout issues
- Prefer Flexbox/Grid for layouts
- Use clearfix for containers
Common Mistakes
- Not clearing floats causing layout break
- Using float for full layouts unnecessarily
- Ignoring clearfix techniques
- Overlapping elements due to float misuse
Conclusion
CSS float is useful for text wrapping and simple layouts, but modern CSS techniques like Flexbox and Grid are preferred for complex layouts.