SVG Sprite Generator
Combine multiple SVG icons into a single sprite file with usage snippets.
このツールについて
SVG Sprite Generator lets you upload multiple SVG files and merges them into one optimized sprite using the <symbol> + <use> pattern — the standard approach for icon systems. Preview each icon in a grid, customize the <symbol> ID for each one, then download the combined sprite.svg. For every icon you also get the HTML <use> snippet ready to paste into your markup, plus a full example showing how to reference the sprite file.
使い方
- 1 Click 'Upload SVG Files' and select one or more .svg files.
- 2 Review the icon previews and edit each symbol ID as needed.
- 3 Click 'Generate Sprite' to build the combined SVG sprite.
- 4 Download the sprite.svg file and add it to your project.
- 5 Copy the <use> snippet for each icon and paste it into your HTML.
What an SVG sprite is and the problem it solves
If a page uses twenty icons, the naive approach is twenty separate .svg files, each fetched over its own HTTP request. An SVG sprite collapses all of them into a single file. Inside that file, every icon becomes a <symbol> with a unique id, and you display any one of them by referencing its id with a <use> element. One request loads the whole set, the browser caches it once, and you stamp icons anywhere you like by id. This tool takes the SVG files you drop in and assembles exactly that structure for you, entirely in your browser — your files are read locally with the FileReader API and never uploaded to any server.
How the generator builds the sprite
When you add an SVG, the tool parses it, reads its viewBox (or falls back to its width and height), and extracts the inner markup — the paths, circles, and groups that actually draw the icon, stripped of the outer <svg> wrapper. It derives an id from the filename: arrow-left.svg becomes icon-arrow-left, with non-alphanumeric characters cleaned up and everything lowercased. You can edit any id in the grid before generating. Clicking Generate Sprite wraps each icon's inner markup in a <symbol id="…" viewBox="…"> and nests them all inside a single hidden root SVG:
<svg xmlns="http://www.w3.org/2000/svg" style="display:none">…</svg>
Preserving each icon's original viewBox on its symbol is the critical detail — it is what lets icons of different native sizes all render correctly when you later display them at any pixel size.
A worked example
Drop in three files: home.svg, search.svg, and user.svg. The grid shows previews with the ids icon-home, icon-search, and icon-user. You rename icon-user to icon-profile in its box, then click Generate. The output is one sprite containing three symbols, and the tool also lists ready-to-paste usage snippets, one per icon, like:
<svg width="24" height="24"><use href="sprite.svg#icon-profile"></use></svg>
You download sprite.svg into your project, drop that snippet wherever you want the profile icon, and it renders at 24×24. Change width and height and the same symbol scales crisply because SVG is vector, not pixels.
Two ways to reference the sprite
The snippets use an external reference, href="sprite.svg#icon-id", which keeps your HTML clean and lets the browser cache the sprite file. There is a trade-off to know. External <use> works in all modern browsers but is subject to the same-origin policy, so the sprite must be served from your own domain, and it adds one network fetch the first time. The alternative is inline embedding: paste the entire generated sprite SVG once near the top of your HTML (it is hidden with display:none), then reference symbols with just href="#icon-id". Inline costs zero extra requests and sidesteps cross-origin issues, at the price of a slightly larger HTML document. For a handful of icons on a single page, inline is simplest; for a shared icon set across many pages, the external file plus caching wins.
Why currentColor is your friend
One of the biggest advantages of sprite icons over icon fonts or PNGs is styling with CSS. If your source SVGs use fill="currentColor" (or stroke), each rendered icon inherits the text color of its surroundings. That means one symbol can appear black in the header, gray in a footer, and white on a colored button without making three files. You can also size, rotate, and animate icons with ordinary CSS. If your icons came out a fixed color and won't recolor, edit the source SVGs to replace hard-coded fills with currentColor before generating.
Common mistakes
- Duplicate ids. Two icons with the same id will collide and only one will show. Because ids derive from filenames, two files named
icon.svgin different folders both becomeicon-icon; rename them in the grid before generating. - Missing or wrong viewBox. Icons authored without a viewBox may render cropped or oddly scaled. Make sure each source SVG has a sensible viewBox so the symbol inherits it.
- Serving the sprite cross-origin. External
<use>won't load a sprite from a different domain or a CDN that lacks the right headers. Host it on your own origin or inline it. - Baked-in colors. Hard-coded fills defeat CSS recoloring. Switch to
currentColorin the sources if you want themeable icons.