Performance: Icons in buttons and inputs
This affects page load speed and rendering performance by adding extra DOM elements and CSS styles for icons inside interactive controls.
<button><svg aria-hidden='true' focusable='false'><use xlink:href='#icon-submit'></use></svg> Submit</button>
<button><img src='icon.png' alt='icon'> Submit</button>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| <img> icons inside buttons | Adds 1+ nodes per icon | Triggers reflow on image load | High paint cost for images | [X] Bad |
| SVG sprite icons inside buttons | Minimal extra nodes | Single layout pass | Low paint cost, scalable | [OK] Good |
| CSS background-image icons | No extra DOM nodes | No reflow on load | Low paint cost | [OK] Good |
| Icon fonts inside inputs | Adds text nodes | Minimal reflow | Low paint cost | [OK] Good |
<div class="input-group"> <span class="input-group-text"><i class="bi bi-envelope"></i></span> <input type="email" class="form-control" placeholder="Email" aria-label="Email"> </div>
.input-group wraps input and icon for inline layout with styling..input-group-text appears on the left side inside a styled box next to the input.<button class="btn btn-primary"> <i class="bi bi-search"></i>Search </button>
<i> tag are correct; button tag is correct..input-group..input-group-text.input-group-text aligns it on the right side and makes it clickable.Pass the test and this pattern moves unknown