Float and clear utilities help you position elements side by side or control how elements wrap around each other. They make layout easier without writing custom CSS.
Float and clear utilities in Bootsrap
float-start float-end float-none clear-start clear-end clear-both
float-start floats element to the left in left-to-right languages.
float-end floats element to the right in left-to-right languages.
clear-* classes stop elements from wrapping around floated elements.
<div class="float-start">Floated left</div> <div>Normal flow</div>
<img src="image.jpg" class="float-end" alt="Example image"> <p>Text wraps on the left side.</p>
<div class="clear-both">This clears floats above it.</div>
This example shows an image floated left with text wrapping around it, a paragraph cleared below the float, and a box floated right with normal text below it.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Float and Clear Utilities Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container mt-4"> <h1>Float and Clear Utilities Demo</h1> <p> <img src="https://via.placeholder.com/100" class="float-start me-3 mb-3" alt="Placeholder image"> This text wraps around the image floated to the start (left). The image uses <code>float-start</code> and margin utilities for spacing. </p> <p class="clear-both"> This paragraph uses <code>clear-both</code> so it appears below the floated image and text wraps. </p> <div class="float-end bg-primary text-white p-2"> Floated to the end (right) </div> <div class="clearfix mb-3"></div> <p> This text flows normally below the floated box on the right. </p> </main> </body> </html>
Float utilities respect the text direction (left-to-right or right-to-left).
Use clear-* classes to prevent layout issues caused by floats.
Combine float utilities with margin utilities for better spacing.
Float utilities position elements left or right easily.
Clear utilities stop elements from wrapping around floats.
They help create simple layouts without custom CSS.
Practice
float-start do to an element?Solution
Step 1: Understand float-start meaning
The classfloat-startin Bootstrap floats an element to the start side of the container, which is left in left-to-right languages.Step 2: Compare options with float-start behavior
Thefloat-startclass floats the element to the left side of its container. This matches 'It floats the element to the left side of its container.' Other options describe floating right, centering, or clearing floats.Final Answer:
It floats the element to the left side of its container. -> Option CQuick Check:
float-start = float left [OK]
- Confusing float-start with float-end
- Thinking float-start centers the element
- Mixing float with clear utilities
Solution
Step 1: Recall Bootstrap clear utility class
Bootstrap uses the classclearfixto clear floats and prevent wrapping issues.Step 2: Check options for correct spelling and usage
clearfixis the correct class name. The other options like float-clear, clear-fix, and clear-start do not exist in Bootstrap.Final Answer:
clearfix -> Option AQuick Check:
Clear floats = clearfix [OK]
- Using float-clear instead of clearfix
- Misspelling clearfix as clear-fix
- Confusing float and clear classes
<div> <div class="float-end">Box A</div> <div>Box B</div> </div>
Solution
Step 1: Understand float-end effect on Box A
The classfloat-endfloats Box A to the right side of the container.Step 2: Analyze Box B position without float
Box B is not floated, so it flows normally. Because Box A is floated right, Box B will appear on the left side, next to Box A, if space allows.Final Answer:
Box A and Box B appear side by side, Box A on the right. -> Option AQuick Check:
float-end floats right, next element flows beside [OK]
- Assuming non-floated elements always go below floats
- Thinking float-end floats left
- Believing floats cause overlap without clearing
<div> <div class="float-start">Left Box</div> <div class="float-end">Content Box</div> </div>
The parent div collapses in height due to floated children. What should be added?
Solution
Step 1: Understand float-start effect on Left Box
Thefloat-starton Left Box andfloat-endon Content Box take both children out of normal flow, causing the parent container to collapse.Step 2: Use clearfix to fix float overlap
Addingclearfixto the parent container clears floats, forcing it to expand and contain the floated children properly.Final Answer:
Add clearfix class to the parent <div>. -> Option DQuick Check:
Clear floats with clearfix on parent [OK]
- Adding float classes to non-floated elements
- Using non-existent clear-start class
- Not clearing floats causing layout break
Solution
Step 1: Float first box left with float-start
The first box usesfloat-startto float left as required.Step 2: Prevent second box wrapping with clearfix
To stop the second box from wrapping around the floated first box, applyclearfixto the second box or its container to clear the float.Final Answer:
First box: float-start, second box: clearfix -> Option BQuick Check:
Use clearfix to clear floats below floated elements [OK]
- Using clear-start which is not a Bootstrap class
- Misspelling clearfix as clear-fix
- Not clearing floats causing wrapping
Ready to prove it?
Pass the test and this pattern moves unknown
