← Back to Bootstrap Course | Chapter 9: Layout Utilities | Lesson 7 of 7

Float

Float utilities push elements to the left or right and let text wrap around them.

In this page:

  1. Float
Syntax
markup
<div class="float-start">left</div>
<div class="float-end">right</div>
<div class="clearfix"></div>

Float

.float-start and .float-end float elements, .float-none resets, and breakpoint versions such as .float-md-end exist. Floated elements leave the normal flow, so clear them with .clearfix on the parent.

For modern layouts prefer flexbox or the grid over floats.

Note: Add clearfix to the container of floated children so it wraps them.

Example: Float

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <div class="clearfix border p-2">
    <div class="float-start bg-info-subtle p-2 me-2">float-start</div>
    <div class="float-end bg-warning-subtle p-2 ms-2">float-end</div>
    <p>Text wraps between the floated boxes and the clearfix parent contains them all.</p>
  </div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Forgetting clearfix
  2. Using floats for whole-page layouts
  3. Using float-left from Bootstrap 4
Chapter Summary
  • float-start and float-end
  • float-none resets
  • Breakpoint versions exist
  • Use clearfix on the parent
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.