Performance: Before pseudo-element
MEDIUM IMPACT
This affects the rendering performance by adding extra elements to the DOM visually, which can increase paint and composite work.
p::before { content: ''; display: inline-block; width: 200px; height: 200px; background-image: url('small-icon.svg'); background-size: contain; background-repeat: no-repeat; }
p::before { content: url('large-image.png'); display: inline-block; width: 200px; height: 200px; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large image in ::before | No extra DOM nodes, but visual layer added | 1 reflow if size not fixed | High paint cost due to large image | [X] Bad |
| Small SVG background in ::before | No extra DOM nodes, visual layer added | No reflow with fixed size | Low paint cost with vector image | [OK] Good |