CSS Float & Clear

Wrap text around images.

✍️ 3 exercises + code challenge in this lesson

float pushes an element to the left or right so text wraps around it, just like an image in a newspaper.

  • float: left / float: right / float: none
  • clear: both makes an element start below any floats.
For page layouts, use Flexbox or Grid instead of float. Float is still perfect for wrapping text around an image.

Key Takeaways: CSS Float & Clear

Mastering CSS Float & Clear helps you write clean and reliable CSS code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

CSS Float & Clear Code Example

CSS
<style>
  img { float: left; margin: 0 14px 8px 0; border-radius: 8px; }
  .footer { clear: both; background: #071A2F; color: white; padding: 8px; }
</style>

<img src="https://picsum.photos/id/1062/120/90" alt="Dog" width="120" height="90">
<p>This text wraps around the floated image. Float was once used for whole page layouts, but today its main job is letting text flow around pictures, just like in a magazine article. Keep typing to see more lines wrap.</p>
<div class="footer">This footer uses clear: both</div>
Free sign-in required · Google login available

CSS Float & Clear Practice Exercises

Check what you learned in “CSS Float & Clear”.

/ 3 solved
Fill in the blank

Float the image to the right.

img {
  float: ;
}
✓ Correct! Not quite. Try again.
Multiple choice

Which property makes an element start below floated elements?

✓ Correct! Not quite. Try again.
Code challenge

Float the image to the left.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services