Performance: Custom icon integration
This affects page load speed and rendering performance by adding extra assets and DOM elements for icons.
<svg class="icon"><use xlink:href="#icon-id"></use></svg> with SVG sprite loaded once
<img src="large-icon.svg" alt="icon"> repeated multiple times in HTML
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple <img> tags for icons | High (one node per icon) | Multiple reflows per icon | High paint cost due to images | [X] Bad |
| SVG sprite with <use> | Low (single sprite + references) | Single reflow | Low paint cost | [OK] Good |
<svg> with <use> referencing an icon ID inside an SVG sprite.<svg class='bi'><use xlink:href='#icon-name' /></svg> uses <svg> and <use xlink:href='#icon-name' /> which is correct. <img src='icon.svg' class='bi'> uses <img> which is not inline SVG. <icon name='custom-icon' /> uses a non-standard <icon> tag. <svg href='icon.svg' class='icon'></svg> incorrectly uses href on <svg>.<svg class='bi' width='2em' height='2em' role='img' aria-label='Star'> <use xlink:href='#star-fill' /> </svg>
class='bi' applies Bootstrap icon styles. Width and height set size to 2em. The <use> references the symbol with id 'star-fill'.role='img' and aria-label='Star' provide screen readers a label. The icon will appear as a filled star sized 2em.<svg class='bi' width='1em' height='1em' aria-label='Heart'> <use href='#heart-fill' /> </svg>
aria-label is present but role='img' is missing, which is needed for screen readers to treat SVG as an image.href is valid in modern browsers (SVG2), so no error there. Width and height with '1em' are valid CSS units. The class attribute is allowed on SVG.role='img' attribute for accessibility -> Option C<button class='btn btn-primary'><svg class='bi text-white' role='img' aria-label='Send'><use xlink:href='#send-fill'/></svg> Send</button> uses text-white on the SVG so the icon color contrasts well on the blue button background. It also includes role='img' and aria-label for accessibility.<button class='btn btn-primary'><svg class='bi text-primary' role='img' aria-label='Send'><use xlink:href='#send-fill'/></svg> Send</button> uses text-primary which is blue, so icon won't contrast on blue button. <button class='btn btn-primary'><img src='send.svg' alt='Send icon'> Send</button> uses an image without inline SVG, losing Bootstrap styling. <button class='btn btn-primary'><svg class='bi'><use xlink:href='#send-fill'/></svg> Send</button> lacks color class and accessibility attributes.Pass the test and this pattern moves unknown