Performance: Avoiding common Bootstrap mistakes
This affects page load speed, rendering performance, and user interaction responsiveness by how Bootstrap is used and customized.
<div class="container"> <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4"> <div class="col">Content</div> <div class="col">Content</div> <div class="col">Content</div> <div class="col">Content</div> </div> </div>
<div class="container"> <div class="row"> <div class="col-6 col-md-4 col-lg-3"> Content </div> <div class="col-6 col-md-4 col-lg-3"> Content </div> <div class="col-6 col-md-4 col-lg-3"> Content </div> <div class="col-6 col-md-4 col-lg-3"> Content </div> </div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using many nested grid columns | High (many divs) | Multiple on resize | Medium | [X] Bad |
| Using responsive row-cols classes | Low (fewer divs) | Single on resize | Low | [OK] Good |
| Loading full Bootstrap CSS/JS | N/A | N/A | High (large CSS/JS) | [X] Bad |
| Custom Bootstrap build with needed parts | N/A | N/A | Low (small CSS/JS) | [OK] Good |
| Overriding styles with !important | N/A | Multiple style recalcs | Medium | [X] Bad |
| Using Bootstrap variables and utilities | N/A | Minimal style recalcs | Low | [OK] Good |
btn plus a style class like btn-primary to work properly.btn-primary alone without btn will not style the button correctly.btn-primary without the base btn class -> Option Bbtn with style classes [OK]btn class with button styles [OK]btn classcol without a number divides space equally among columns.<div class='row'><div class='col'>...</div><div class='col'>...</div><div class='col'>...</div></div> uses col three times inside a row, which creates three equal columns responsively.col inside a row for equal columns -> Option Acol inside row [OK]col for equal columns inside a row [OK]col-4 without a rowrow container<div class='container'>
<div class='row'>
<div class='col-md-6 col-sm-12'>Left</div>
<div class='col-md-6 col-sm-12'>Right</div>
</div>
</div>col-md-6 means half width on medium (≥768px) and larger screens; col-sm-12 means full width on small (≥576px) screens.col-sm and col-md breakpoints<nav class='navbar navbar-expand-lg'>
<div class='container-fluid'>
<a class='navbar-brand' href='#'>Brand</a>
<button class='navbar-toggler' type='button' data-toggle='collapse' data-target='#navbarNav'>
<span class='navbar-toggler-icon'></span>
</button>
<div class='collapse navbar-collapse' id='navbarNav'>
<ul class='navbar-nav'>
<li class='nav-item'><a class='nav-link' href='#'>Home</a></li>
</ul>
</div>
</div>
</nav>data-toggle and data-target to data-bs-toggle and data-bs-target.data-toggle and data-target, which won't work in Bootstrap 5.data-toggle and data-target instead of data-bs-toggle and data-bs-target -> Option Cdata-bs-* attributes [OK]data-bs-toggle and data-bs-target in Bootstrap 5 [OK]mx-auto applies automatic horizontal margins, centering the element inside its container.max-width: 24rem; limits the card's width but allows it to shrink on smaller screens, avoiding overflow.<div class='card mx-auto' style='max-width: 24rem;'>...</div> uses mx-auto and max-width, which is the best practice to center and limit width responsively.mx-auto and limit width with max-width [OK]mx-auto and max-width for centered responsive cards [OK]text-center which centers text, not the cardPass the test and this pattern moves unknown