Inline SVG vs data-URI icons

Renders the same icons four ways in your browser and times DOM insertion, style + layout, first paint and a re-layout. Every round shuffles the order; the first round is a discarded warm-up.

Waiting for the first run…

Total = DOM + CSS insertion, forced style + layout, and the rendering work of the next frame (median).

Results appear here after each round.
DOM + CSS insertStyle + layoutPaint frame

How each method scales

Median total time at 250 to 10,000 icons, using the settings above (half the rounds per step).

Press “Scaling sweep” to see how render time grows with icon count.

What the four methods are

  • Inline <svg> — a full <svg><path d="…"/></svg> per icon, stroked with currentColor.
  • Inline <svg><use> — a tiny <svg><use href="#icon"/></svg> pointing at a sprite of symbols already in the page.
  • Data URI background — an empty <i> with background-image: url("data:image/svg+xml,…"). Colour is baked into the SVG.
  • Data URI mask — the same URI as mask-image over background-color: currentColor, so the icon can still be recoloured with CSS.

What the phases measure

  • DOM + CSS insert — writing the generated stylesheet and innerHTML (HTML parsing, node creation). String building is excluded.
  • Style + layout — a forced synchronous layout via offsetHeight.
  • Paint frame — from the next requestAnimationFrame to a MessageChannel task after it: the frame's rendering work, without the wait for vsync.
  • Re-layout — icons grow 1.5×, forcing layout and repaint of what's already there.

Caveats

  • Browsers may decode data-URI images off the main thread or after the measured frame, so their first-paint cost can be under-counted. Confirm big differences in the DevTools Performance panel.
  • Identical data URIs share one decoded image. “Fresh data URIs” adds a per-round comment so each round pays for parsing again — the worst case, like a cold page load.
  • Inline SVG costs grow with nodes and HTML bytes; data URIs move the bytes into CSS and the work into image decoding and rasterising.
  • Close other heavy tabs and run a few times; timer precision is reduced in some browsers.