Performance: List group with badges
This affects the rendering speed and visual stability of list components with badges in the browser.
<ul class="list-group"> <li class="list-group-item d-flex justify-content-between align-items-center"> Messages <span class="badge bg-primary rounded-pill" style="min-width:2.5rem; text-align:center;">99+</span> </li> <li class="list-group-item d-flex justify-content-between align-items-center"> Notifications <span class="badge bg-primary rounded-pill" style="min-width:2.5rem; text-align:center;">1000</span> </li> <li class="list-group-item d-flex justify-content-between align-items-center"> Tasks <span class="badge bg-primary rounded-pill" style="min-width:2.5rem; text-align:center;">5</span> </li> </ul>
<ul class="list-group"> <li class="list-group-item">Messages <span class="badge bg-primary">99+</span></li> <li class="list-group-item">Notifications <span class="badge bg-primary">1000</span></li> <li class="list-group-item">Tasks <span class="badge bg-primary">5</span></li> </ul>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Variable width badges inside list items | Low (few nodes) | Multiple reflows on badge content change | Medium due to layout shifts | [X] Bad |
| Fixed width badges with flexbox layout | Low (few nodes) | Single reflow on initial render | Low paint cost due to stable layout | [OK] Good |
list group with badges in Bootstrap?d-flex justify-content-between align-items-center makes the list item a flex container that spaces content horizontally and centers vertically.<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center">
Messages
<span class="badge bg-primary rounded-pill">14</span>
</li>
</ul>list-group-item with flex classes arranges content horizontally with space between.bg-primary for blue background and rounded-pill for pill shape, placed on the right side.<ul class="list-group">
<li class="list-group-item">
Notifications
<span class="badge badge-primary">5</span>
</li>
</ul>bg-primary for badge background color, not badge-primary.bg-danger for red, bg-warning for yellow, and bg-success for green backgrounds.bg-* classes, not badge-* or text-* for background colors.Pass the test and this pattern moves unknown