Bundles SVG icons from a folder into a single SVG sprite file. Zero dependencies, recursive scanning, id isolation, IconName types. React, Vue, Svelte and Angular — through Vite, webpack, a CLI, or Next.js without a plugin.
Everything below is built by the package itself, from the icons in
demo/icons.
npm install -D svg-sprite-kit
This grid is the sprite: every tile is a <use> pointing at
a symbol. Click a tile to copy its #id. The same page, with search included, is
generated for you by the demoFilePath option.
Nothing matches.
A symbol's id is the file path, with the
symbolId template deciding the shape of it.
| File | Default [dir]-[name] | Reference |
|---|---|---|
arrow-left.svg | arrow-left | <use href="/sprite.svg#arrow-left"> |
ui/nav/menu.svg | ui-nav-menu | <use href="/sprite.svg#ui-nav-menu"> |
gradient/sun.svg | gradient-sun | <use href="/sprite.svg#gradient-sun"> |
isolateIds — gradients stop stealing each otherBoth icons were exported with id="a" for their gradient, which is
what drawing tools produce. In one document the browser resolves both references to whichever
id it met first.
id="a" came first in the document wins.isolateClasses — one .st0 no longer winsCSS inside a <symbol> is not scoped to that symbol. Illustrator
names every icon's class .st0, so in a shared document the last rule in the file
repaints all of them.
currentColor — icons follow the textThe icons on the left keep the colors baked into the files. On the right the same
icons were built with currentColor: true, so CSS on the parent drives them. Pick
a color:
And this is why the option is off by default. A two-tone
icon loses the second tone — here the white glyph is repainted along with the disc behind it.
Gradients, on the other hand, survive: url(...) references and
stop-color are left alone, which is why the sun looks the same either way.
url(...) is left alone.Three sprites, one command each, all from the same folder of icons — no manual editing involved.
svg-sprite-kit ./demo/icons -o ./docs/sprite.svg svg-sprite-kit ./demo/icons -o ./docs/sprite-raw.svg --no-isolate-ids --no-isolate-classes svg-sprite-kit ./demo/icons -o ./docs/sprite-current.svg --current-color