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-muted 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.
Secure file sharingOverdue
Our team has done this many times, so you never have to guess.
<div class="card">
<div class="card-header hp-cf clearfix">
<span class="hp-fl float-start px-2 font-semibold">Secure file sharing</span> <span class="badge text-bg-success float-end mt-1">Overdue</span>
</div>
<div class="card-body small">
Our team has done this many times, so you never have to guess.
</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.
"Work that moves itself forward"
Start free, upgrade when you grow and cancel any time with one click. We measure success by how many customers come back and tell their friends. We keep things simple, so you can focus on what matters to you. Plan projects, track progress and share updates without another status meeting.
We keep things simple, so you can focus on what matters to you.
Next section starts on a clean line
<article class="hp-cf clearfix">
<blockquote class="hp-fl sm:float-end sm:ms-4 mb-2 p-4 text-base italic">"Work that moves itself forward"</blockquote>
<p class="mb-2">Start free, upgrade when you grow and cancel any time with one click. We measure success by how many customers come back and tell their friends. We keep things simple, so you can focus on what matters to you. Plan projects, track progress and share updates without another status meeting.</p>
<p class="mb-0">We keep things simple, so you can focus on what matters to you.</p>
</article>
<h3 class="h6 mt-4 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.
1 days ago
Zoe Sato
Onboarding guides and live chat help new colleagues get going on day one.
<div class="hp-cf clearfix">
<img src="../assets/img/avatar-4.svg" alt="Zoe Sato" width="40" height="40" class="rounded-full float-start me-2"> <small class="hp-fl float-end px-2 text-muted">1 days ago</small> <strong class="block">Zoe Sato</strong>
<p class="small mb-0">Onboarding guides and live chat help new colleagues get going on day one.</p>
</div>
9Responsive floats
float-md-start and float-md-end only float from the md breakpoint; below it the boxes stack.
An icon floated left, a time stamp floated right and the message in between.
34 min ago
Start free, upgrade when you grow and cancel any time with one click.
<div class="hp-cf clearfix bg-page">
<span class="hp-fl float-start me-2 px-2 py-1 text-primary-ink"><i class="bi bi-bell-fill" aria-hidden="true"></i></span> <small class="float-end text-muted">34 min ago</small>
<p class="small mb-0">Start free, upgrade when you grow and cancel any time with one click.</p>
</div>
16Pricing card label
A floated badge in the top corner of a pricing card body.
A product image floated to the end of a card body with the description flowing around it.
Business plan
We listen first, then build a plan around what you actually need.
<div class="card">
<div class="card-body hp-cf clearfix">
<img src="../assets/img/product-3.svg" alt="Business plan" width="110" height="110" class="hp-fl float-end ms-4 rounded-md">
<h3 class="h6">Business plan</h3>
<p class="small mb-0">We listen first, then build a plan around what you actually need.</p>
</div>
</div>
20Sidebar and content
A classic two-column float layout: a floated nav box and a content box; clearfix closes the row.
The small habits that make a big difference
Plan projects, track progress and share updates without another status meeting. We measure success by how many customers come back and tell their friends. Thousands of customers already trust us, and we work hard to keep it that way. Set up in an afternoon, connect the tools you use and invite your team.
<div class="hp-cf clearfix">
<nav class="hp-fl sm:float-start sm:me-4 mb-2 p-2" aria-label="Section">
<ul class="nav flex-col 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">The small habits that make a big difference</h3>
<p class="small mb-0">Plan projects, track progress and share updates without another status meeting. We measure success by how many customers come back and tell their friends. Thousands of customers already trust us, and we work hard to keep it that way. Set up in an afternoon, connect the tools you use and invite your team.</p>
</div>
</div>