Performance: SVG icon usage
This affects page load speed and rendering performance by how SVG icons are included and reused in the page.
<svg><use xlink:href="#icon1"></use></svg>\n<svg><use xlink:href="#icon2"></use></svg>\n<svg><use xlink:href="#icon3"></use></svg>\n<!-- SVG sprite defined once in HTML -->
<img src="icon1.svg" alt="icon">\n<img src="icon2.svg" alt="icon">\n<img src="icon3.svg" alt="icon">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple <img> SVG files | High (one node per icon) | Multiple reflows (each icon loads separately) | High (each icon repaints) | [X] Bad |
| Single inline SVG sprite with <use> | Low (one sprite + references) | Single reflow | Low (reuse of shapes) | [OK] Good |
fill="currentColor" makes the SVG icon inherit the current text color automatically.<svg class="bi bi-star" width="2rem" height="2rem" fill="currentColor"><use xlink:href="#star" /></svg>
<svg role="img" aria-label="Search icon"><path d="M10 10 L20 20" /></svg>
Pass the test and this pattern moves unknown