Performance: Badge component
Badge components affect page load speed and rendering performance by adding extra DOM elements and CSS styles that can trigger layout and paint operations.
<span class="badge bg-primary">99+ New</span>
<span class="badge bg-primary">99+</span><span class="badge bg-danger">New</span>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple badges for related info | More nodes | Multiple reflows if updated separately | Multiple paints | [X] Bad |
| Single combined badge | Fewer nodes | Single reflow | Single paint | [OK] Good |
| Frequent badge text updates without batching | Same nodes | Many reflows | Many paints | [X] Bad |
| Batched badge updates with debounce | Same nodes | Few reflows | Few paints | [OK] Good |
badge component?span with class badge plus a background color class like bg-primary.span.badge.bg-primary [OK]<button type="button" class="btn btn-secondary">Messages <span class="badge bg-danger">5</span></button>
btn btn-secondary which styles it gray. The badge uses badge bg-danger which styles it red.<span class="badge badge-primary">99</span>
bg-primary, not badge-primary.span tag is correct, number size is fine, and the closing tag is present.<a href="#" class="nav-link">Notifications <?></a>What should replace
<?>?span with badge and color class like bg-info.aria-label describes the badge meaning for screen readers, improving accessibility.Pass the test and this pattern moves unknown