Bootstrap | Float utilities with Examples
Bootstrap provides us a series of float utility classes, that allows an element to float left, right, or make it not to float, just like CSS float property. In addition to this, bootstrap provides responsive float classes, that makes an element float based on the viewport size.
Bootstrap breakpoints:
- sm: Viewport greater than 576px.
- md: Viewport greater than 768px.
- lg: Viewport greater than 992px.
- xl: Viewport greater than 1200px.
Common Float Classes
- float-left: It makes the element to float left on all viewport sizes.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.head{color: green;text-align: center;}div.box{height: 150px;width: 150px;border: 1px dashed black;background: #E3F2FD;margin: 20px;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Hello, world!</title></head><body><divclass="container"><!-- For making div reponsive --><h1class="head">GeeksForGeeks</h1><!-- float-left, bootstrap class --><divclass="float-left box"></div><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon, Adobeetc with a free online placement preparationcourse. The course focuses on various MCQ's& Coding question likely to be asked in theinterviews & make your upcoming placementseason efficient and successful.</p></div><!-- Link JavaScript --><!-- jQuery first, then Popper.js, then Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:

- float-right: It makes the element to float right on all viewport sizes.
Example:
<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.head{color: green;text-align: center;}div.box{height: 150px;width: 150px;border: 1px dashed black;background: #E3F2FD;margin: 20px;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Hello, world!</title></head><body><divclass="container"><!-- For making div reponsive --><h1class="head">GeeksForGeeks</h1><!-- float-right, bootstrap class --><divclass="float-right box"></div><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon, Adobeetc with a free online placement preparationcourse. The course focuses on various MCQ's& Coding question likely to be asked in theinterviews & make your upcoming placementseason efficient and successful.</p></div><!-- Link JavaScript --><!-- jQuery first, then Popper.js, then Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
- float-none: It makes the element not to float across all viewport sizes.
Example:<!DOCTYPE html><html><head><!-- Custom CSS --><style>h1.head{color: green;text-align: center;}div.box{height: 150px;width: 150px;border: 1px dashed black;background: #E3F2FD;margin: 20px;}</style><!-- Bootstrap CSS --><linkrel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"crossorigin="anonymous"><title>Hello, world!</title></head><body><divclass="container"><!-- For making div reponsive --><h1class="head">GeeksForGeeks</h1><!-- float-none, bootstrap class --><divclass="float-none box"></div><p>Prepare for the Recruitment drive of productbased companies like Microsoft, Amazon, Adobeetc with a free online placement preparationcourse. The course focuses on various MCQ's& Coding question likely to be asked in theinterviews & make your upcoming placementseason efficient and successful.</p></div><!-- Link JavaScript --><!-- jQuery first, then Popper.js, then Bootstrap JS --><scriptsrc="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"crossorigin="anonymous"></script><scriptsrc="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"crossorigin="anonymous"></script></body></html>chevron_rightfilter_noneOutput:
Responsive Float Classes:
| Class | Description |
|---|---|
| float-sm-left | It makes the element to float left on viewport of size greater than 576px (sm). |
| float-sm-right | It makes the element to float right on viewport of size greater than 576px (sm). |
| float-sm-none | It makes the element not to float on viewport of size greater than 576px (sm). |
| float-md-left | It makes the element to float left on viewport of size greater than 768px (md). |
| float-md-right | It makes the element to float right on viewport of size greater than 768px (md). |
| float-md-none | It makes the element not to float on viewport of size greater than 768px (md). |
| float-lg-left | It makes the element to float left on viewport of size greater than 992px (lg). |
| float-lg-right | It makes the element to float right on viewport of size greater than 992px (lg). |
| float-lg-none | It makes the element not to float on viewport of size greater than 992px (lg). |
| float-xl-left | It makes the element to float left on viewport of size greater than 1200px (xl). |
| float-xl-right | It makes the element to float right on viewport of size greater than 1200px (xl). |
| float-xl-none | It makes the element not to float on viewport of size greater than 1200px (xl). |
Example: float-md-right.
<!DOCTYPE html> <html> <head> <!-- Custom CSS --> <style> h1.head{ color: green; text-align: center; } div.box{ height: 150px; width: 150px; border: 1px dashed black; background: #E3F2FD; margin: 20px; } </style> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> <title>Hello, world!</title> </head> <body> <div class="container"><!-- For making div reponsive --> <h1 class="head">GeeksForGeeks</h1> <!-- float-md-right, bootstrap class --> <div class="float-md-right box"> </div> <p> Prepare for the Recruitment drive of product based companies like Microsoft, Amazon, Adobe etc with a free online placement preparation course. The course focuses on various MCQ's & Coding question likely to be asked in the interviews & make your upcoming placement season efficient and successful. </p> </div> <!-- Link JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script> </body> </html> |
Output:
Note: We can use more that one float utility class simultaneously to get the desired results. For example we may set float-right and float-md-left, to float element to right on viewport size less than 768px and float to left when viewport is greater than 768px.
Example:
<!DOCTYPE html> <html> <head> <!-- Custom CSS --> <style> h1.head{ color: green; text-align: center; } div.box{ height: 150px; width: 150px; border: 1px dashed black; background: #E3F2FD; margin: 20px; } </style> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> <title>Hello, world!</title> </head> <body> <div class="container"><!-- For making div reponsive --> <h1 class="head">GeeksForGeeks</h1> <!-- float-right float-md-left, bootstrap classes --> <div class="float-right float-md-left box"> </div> <p> Prepare for the Recruitment drive of product based companies like Microsoft, Amazon, Adobe etc with a free online placement preparation course. The course focuses on various MCQ's & Coding question likely to be asked in the interviews & make your upcoming placement season efficient and successful. </p> </div> <!-- Link JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script> </body> </html> |
Output:
Recommended Posts:
- Flexbox utilities in bootstrap with examples
- Screen Reader utilities in bootstrap with Examples
- Bootstrap 4 | Utilities
- BootStrap | Text Utilities (Alignment, Wrapping, Weight etc.)
- Popovers in bootstrap with examples
- Bootstrap Buttons with Examples
- Containers in Bootstrap with examples
- Spacing in Bootstrap with Examples
- Borders in bootstrap with examples
- Bootstrap | figure class with Examples
- List group in bootstrap with examples
- Vertical alignment in Bootstrap with Examples
- BootStrap | Positioning an element with Examples
- Bootstrap | Sizing an element with Examples
- Input Groups in Bootstrap with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



