◩ WebTools

SVG sprite

A whole icon set in one file, ready for <use>.

Twenty icons are twenty requests, and each one costs the browser more than it weighs. A sprite puts them all in one file as <symbol>, and then each is used with <use href="#icon-arrow">.

While it is at it, leaving the currentColor option on strips the colours from inside, so the CSS that shows them decides: the same icon serves a light button and a dark one without a duplicate.

How to use it

  1. Drop in all the icons at once.
  2. Add a prefix if you want the ids not to clash with anything.
  3. Process: one sprite.svg comes out.

Frequently asked questions

How do I use it?
Paste the contents at the top of the <body>, then call each icon with <svg><use href="#its-id"></use></svg>. If you keep it as a separate file, the reference has to be sprite.svg#its-id.
Where do the ids come from?
From each file name, lowercased and hyphenated, with the prefix in front. If two files end up with the same name, the second gets a number.
Why are my icons black?
Because with currentColor on they inherit the text colour. Set a colour in the CSS of whatever uses them, or untick the option to keep the original colours.

Related tools