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 quote floated to the end of the paragraph; the article wrapper is cleared so the next section starts below.
"Stand with families in need"
Volunteers give their time in schools, shelters and food banks every week. Monthly gifts let us plan ahead and respond quickly when disaster strikes. Our team has done this many times, so you never have to guess.
You receive photos and updates showing exactly what your donation achieved.
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">"Stand with families in need"</blockquote>
<p class="mb-2">Volunteers give their time in schools, shelters and food banks every week. Monthly gifts let us plan ahead and respond quickly when disaster strikes. Our team has done this many times, so you never have to guess.</p>
<p class="mb-0">You receive photos and updates showing exactly what your donation achieved.</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.
15 min ago
Ravi Whitaker
Ninety cents of every dollar goes directly to the projects you support.
<div class="hp-cf clearfix">
<img src="../assets/img/avatar-11.svg" alt="Ravi Whitaker" width="40" height="40" class="rounded-circle float-start me-2"> <small class="hp-fl float-end px-2 text-body-secondary">15 min ago</small> <strong class="d-block">Ravi Whitaker</strong>
<p class="small mb-0">Ninety cents of every dollar goes directly to the projects you support.</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.
yesterday
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" aria-hidden="true"></i></span> <small class="float-end text-body-secondary">yesterday</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.
Meet the partners behind our water projects
Companies can match employee donations and double their impact. Our annual report is independently audited and published in full. Thousands of donors already trust us, and we work hard to keep it that way. We keep things simple, so you can focus on what matters to you.
<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">Meet the partners behind our water projects</h3>
<p class="small mb-0">Companies can match employee donations and double their impact. Our annual report is independently audited and published in full. Thousands of donors already trust us, and we work hard to keep it that way. We keep things simple, so you can focus on what matters to you.</p>
</div>
</div>