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.
Business accountsCancelled
Open a business account online in about ten minutes, with no branch visit.
<div class="card">
<div class="card-header hp-cf clearfix">
<span class="hp-fl float-start px-2 fw-semibold">Business accounts</span> <span class="badge text-bg-success float-end mt-1">Cancelled</span>
</div>
<div class="card-body small">
Open a business account online in about ten minutes, with no branch visit.
</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.
"Finance tools your accountant will love"
Friendly people answer your questions quickly, by phone, chat or email. Invoices go out with a payment link, so customers can pay you in one click. Our team has done this many times, so you never have to guess. Send and receive money in more than 30 currencies at fair exchange rates.
Every detail is handled by people who care about getting it right.
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">"Finance tools your accountant will love"</blockquote>
<p class="mb-2">Friendly people answer your questions quickly, by phone, chat or email. Invoices go out with a payment link, so customers can pay you in one click. Our team has done this many times, so you never have to guess. Send and receive money in more than 30 currencies at fair exchange rates.</p>
<p class="mb-0">Every detail is handled by people who care about getting it right.</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
Chloe Ortega
Every payment appears instantly, with receipts matched automatically.
An icon floated left, a time stamp floated right and the message in between.
42 min ago
Start in minutes and get help from a real person whenever you need it.
<div class="hp-cf clearfix bg-body">
<span class="hp-fl float-start me-2 px-2 py-1 text-primary"><i class="bi bi-bell-fill" aria-hidden="true"></i></span> <small class="float-end text-body-secondary">42 min ago</small>
<p class="small mb-0">Start in minutes and get help from a real person whenever you need it.</p>
</div>
16Pricing card label
A floated badge in the top corner of a pricing card body.
A classic two-column float layout: a floated nav box and a content box; clearfix closes the row.
What to look for in a business account
Friendly people answer your questions quickly, by phone, chat or email. Real people answer your questions around the clock, every day of the year. Invoices go out with a payment link, so customers can pay you in one click. We measure success by how many members come back and tell their friends.
<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">What to look for in a business account</h3>
<p class="small mb-0">Friendly people answer your questions quickly, by phone, chat or email. Real people answer your questions around the clock, every day of the year. Invoices go out with a payment link, so customers can pay you in one click. We measure success by how many members come back and tell their friends.</p>
</div>
</div>