CHAPTER 25
CSS Float
Learn how the float property positions elements to the left or right and understand the role of clear.
01. What is CSS Float?
The float property moves an element to the left or right side of its container.
Text and inline content can flow around a floated element.
The clear property prevents elements from wrapping around floated elements.
02. Syntax
selector {
float: left;
}
selector {
clear: both;
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.image {
float: left;
width: 140px;
height: 140px;
margin-right: 20px;
background: #2563eb;
}
.clear {
clear: both;
}
</style>
</head>
<body>
<div class="image"></div>
<p>
This paragraph can flow around the floated element.
Float was commonly used for image and text layouts
before modern Flexbox and Grid layouts became popular.
</p>
<div class="clear"></div>
</body>
</html>
04. Important Points
✓
float can move an element left or right.
✓
clear prevents wrapping around floated elements.
✓
Float is still useful in specific content layouts.
✓
Modern layouts generally use Flexbox or Grid for page structure.
05. Common Mistakes
⚠
Using float for complete modern website layouts.
⚠
Forgetting to clear floated elements when necessary.
⚠
Creating difficult responsive layouts using many floats.
06. Real World Use
Float can be useful for wrapping text around images and maintaining older website layouts.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Text Around an Image
Create a square element floated to the left and write a paragraph that flows around it.