A clearfix makes a parent element wrap around its floated children again, so borders, backgrounds and the content that follows stay where you expect. The examples outline every parent with a dashed border and every floated box with a solid one, so you can see the helper at work.
1Two floated buttons
The parent wraps a float-start and a float-end button, so its dashed border surrounds both.
Dashed border: the .clearfix parent. It keeps its height even though both children float.
<div class="hp-cf clearfix">
<button type="button" class="btn btn-outline-secondary float-start">Back</button>
<button type="button" class="btn btn-primary float-end">Continue</button>
</div>
<p class="small text-body-secondary mt-2 mb-0">Dashed border: the .clearfix parent. It keeps its height even though both children float.</p>
2With and without clearfix
Side by side comparison: without the helper the parent collapses to its padding and the float hangs out.
A title floated left and a status badge floated right inside a card header.
Nutrition plansOn hold
We keep things simple, so you can focus on what matters to you.
<div class="card">
<div class="card-header hp-cf clearfix">
<span class="hp-fl float-start px-2 fw-semibold">Nutrition plans</span> <span class="badge text-bg-success float-end mt-1">On hold</span>
</div>
<div class="card-body small">
We keep things simple, so you can focus on what matters to you.
</div>
</div>
5Toolbar
A floated button group and a floated search field share one toolbar row.
A quote floated to the end of the paragraph; the article wrapper is cleared so the next section starts below.
"The community that makes you stronger"
Our recovery spa has a sauna, cold plunge and massage rooms. Nutrition plans fit your routine and the food you actually enjoy. Friendly people answer your questions quickly, by phone, chat or email. Clear prices, honest advice and no surprises along the way.
Small group classes mean your coach knows your name and your form.
Next section starts on a clean line
<article class="hp-cf clearfix">
<blockquote class="hp-fl float-sm-end ms-sm-3 mb-2 p-3 fs-6 fst-italic">"The community that makes you stronger"</blockquote>
<p class="mb-2">Our recovery spa has a sauna, cold plunge and massage rooms. Nutrition plans fit your routine and the food you actually enjoy. Friendly people answer your questions quickly, by phone, chat or email. Clear prices, honest advice and no surprises along the way.</p>
<p class="mb-0">Small group classes mean your coach knows your name and your form.</p>
</article>
<h3 class="h6 mt-3 mb-0">Next section starts on a clean line</h3>
8Comment with avatar
A comment row with a floated avatar and a floated time stamp.
yesterday
Felix Patel
Pause or change your membership any time, with no long contracts.
<div class="hp-cf clearfix">
<img src="../assets/img/avatar-9.svg" alt="Felix Patel" width="40" height="40" class="rounded-circle float-start me-2"> <small class="hp-fl float-end px-2 text-body-secondary">yesterday</small> <strong class="d-block">Felix Patel</strong>
<p class="small mb-0">Pause or change your membership any time, with no long contracts.</p>
</div>
9Responsive floats
float-md-start and float-md-end only float from the md breakpoint; below it the boxes stack.
A product image floated to the end of a card body with the description flowing around it.
Yoga retreat
Our team has done this many times, so you never have to guess.
<div class="card">
<div class="card-body hp-cf clearfix">
<img src="../assets/img/product-3.svg" alt="Yoga retreat" width="110" height="110" class="hp-fl float-end ms-3 rounded">
<h3 class="h6">Yoga retreat</h3>
<p class="small mb-0">Our team has done this many times, so you never have to guess.</p>
</div>
</div>
20Sidebar and content
A classic two-column float layout: a floated nav box and a content box; clearfix closes the row.
HIIT twice a week: how hard is hard enough?
Nutrition plans fit your routine and the food you actually enjoy. We keep things simple, so you can focus on what matters to you. More than sixty classes a week, from sunrise yoga to late-night spin.
<div class="hp-cf clearfix">
<nav class="hp-fl float-sm-start me-sm-3 mb-2 p-2" aria-label="Section">
<ul class="nav flex-column small">
<li class="nav-item"><a class="nav-link active py-1" aria-current="page" href="#">Overview</a></li>
<li class="nav-item"><a class="nav-link py-1" href="#">Members</a></li>
<li class="nav-item"><a class="nav-link py-1" href="#">Billing</a></li>
</ul>
</nav>
<div class="overflow-hidden">
<h3 class="h6">HIIT twice a week: how hard is hard enough?</h3>
<p class="small mb-0">Nutrition plans fit your routine and the food you actually enjoy. We keep things simple, so you can focus on what matters to you. More than sixty classes a week, from sunrise yoga to late-night spin.</p>
</div>
</div>