Skip to content
Justice Tech School

Float and Clear

float: left or right takes an element out of normal flow and lets text wrap around it. It was once used for whole page layouts but is now mainly for images wrapped by text.

clear: both stops an element from sitting next to a float. A parent that only contains floated children collapses, which you can fix with overflow: auto, display: flow-root, or a clearfix.

Example
<style>
  .pic { float: left; width: 80px; height: 80px; margin: 0 12px 6px 0; background: #fb923c; border-radius: 8px; }
  .wrap { border: 2px solid #94a3b8; display: flow-root; padding: 8px; }
  .after { clear: both; background: #e2e8f0; padding: 6px; }
</style>
<div class="wrap">
  <div class="pic"></div>
  <p>Text wraps around the floated box. Keep writing and the lines flow beside it until they pass its bottom edge, then run full width again.</p>
</div>
<p class="after">Cleared paragraph</p>

Exercise

Place the box on the right with text wrapping around it.

.pic {
  : right;
}

Quiz Test

Which modern layout tools replaced floats for page layout?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.