Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Floating & Clearing | CSS Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Course

Lesson 12 of 50

·css

Floating & Clearing

8 mins

Course progress24%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • `float` removes the element from the normal document flow.
  • Use the **clearfix** hack (`.clearfix::after { content:""; display:table; clear:both; }`) when many floats are stacked.
  • Prefer Flexbox/Grid for layout; use float only for media‑wrapping.

Historically, float let text wrap around images.

  • float:left or float:right – element is taken out of normal flow and moves to either side.
  • clear:left|right|both – forces an element to start below floated elements.

Modern layouts rarely need floats; Flexbox/Grid are preferred. However, floats are still needed for inline image wrap.


Example: Image with text wrap

<img src="portrait.jpg" alt="Portrait" style="float:left; margin:0 1rem 1rem 0;" width="150" />
<p>Long paragraph that wraps around the image...</p>
Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS CourseBrowse activities
Previous lessonPositioningContinue to lesson 13Overflow & ScrollbarsBack to CSS Course curriculum