Bootstrap - Clearfix

This chapter discusses the clearfix feature of helper classes. The clearfix feature in Bootstrap is used to clear floated elements within a container. When elements within a container are floated, the container's height can sometimes be collapsed, causing issues with the layout.

Here's an example of how to use the .clearfix class in Bootstrap:


The example below shows the usage of clearfix. Without the clearfix, the wrapping div would not span around the buttons which would cause a broken layout.

You can edit and try running this code using the Edit & Run option.

<!DOCTYPE html>
<html lang="en">
       <title>Bootstrap - Helper - Clearfix</title>
       <meta charset="UTF-8">
       <meta http-equiv="X-UA-Compatible" content="IE=edge">
       <meta name="viewport" content="width=device-width, initial-scale=1.0">
       <link href="" rel="stylesheet">
       <script src=""></script>
        <h4>Clearfix example</h4><br>
          <div class="bg-success clearfix">
          <button type="button" class="btn btn-secondary float-start">Button floated left</button>
          <button type="button" class="btn btn-secondary float-end">Button floated right</button>
Kickstart Your Career

Get certified by completing the course

Get Started