An SVG sprite is a single SVG file that holds several drawings. A web page can display any one of them by cropping a rectangle from a traditional sprite sheet or by referencing a named drawing in a symbol sprite. The same file can supply the icons for an entire site.
Consider a site that shows a magnifying glass in its header, search field, and empty-results message. With a symbol sprite, all three can reference icons.svg#icon-search. Each instance can have its own size, and a stroke painted with currentColor can follow the surrounding text. Redraw the magnifying glass once and all three pick up the change.
When should you use a sprite?
- SVG sprite
- A good fit for a recurring set of interface icons. An external sprite can be fetched once and reused from cache across pages. Each symbol can keep its own colors, strokes, and drawing area. The first page downloads the whole set, even if it uses only one icon. Updating a versioned sprite also means downloading a new copy of the set.
- Individual SVG files
- A good fit for a logo or an illustration that appears on a single page. An
<img>is simple to place and label, and each drawing can be loaded and cached independently. A toolbar with ten different files can require ten first-time image requests. To style individual paths from the page, you can inline the SVG, which adds its markup wherever you place it. - Icon font
- A good fit when a project already uses a font of single-color glyphs that scale and align with text. One font file supplies the set, and CSS controls size and color. The mapping between each icon and its character has to stay in sync. A missing font can leave an empty square, and artwork with independently colored parts is easier to express in SVG.
Build the same four-icon toolbar two ways
You'll work with Search, Folder, Checked Folder, and Close, each drawn on a 24 × 24 grid. First you'll display Folder by sliding a sheet one tile to the left. Then you'll display it by referencing #icon-folder. The buttons look the same, but the difference becomes clear when you resize a button or reorder the file.
When you're ready to make your own sprite, start with the four individual SVGs in the download. Pick whichever route fits how you work: assemble them in the IconVectors editor, give an MCP assistant the filenames, or run a repeatable PowerShell build. All three use IconVectors 2.30 for Windows. You can try the browser examples with just the ZIP and a local web server.
Get the toolbar example files
Use the individual icons to build your first sprite in IconVectors. Open the finished sprites alongside your own to compare the markup and the rendered toolbar.
To run the demo locally, extract the ZIP and open a terminal beside demo.html. Run python -m http.server 8000, then visit http://localhost:8000/demo.html. This serves the page and its sprites from the same origin.
- demo.html Browser demo
- icons.svg Editable symbol sprite
- strip.svg Legacy sheet
- views.svg Named views
- stack.svg CSS target stack
- README.md Setup and exercises
- individual/
- close.svg
- folder-checked.svg
- folder.svg
- search.svg
Crop one icon from a legacy sheet with CSS
The original CSS sprite technique gathered toolbar images and hover states into one bitmap. Each button showed a fixed-size window onto that image. The same technique works with a vector sheet. To display Folder, give the button a 24 px window and shift the sheet 24 px to the left.
In strip.svg, the root drawing area is 96 units wide and 24 high. Draw each icon in its own 24 × 24 coordinate system and translate its group horizontally by 0, 24, 48, or 72 units. Here's the beginning of the second tile. The complete file in the ZIP contains all four groups.
<svg xmlns="http://www.w3.org/2000/svg" width="96" height="24" viewBox="0 0 96 24">
<!-- Search occupies the first 24 units. -->
<g transform="translate(24 0)">
<path d="M3 7a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"
fill="#46BFC1" stroke="#154858" stroke-width="1.5"/>
</g>
<!-- Checked Folder and Close follow. -->
</svg>
Give the HTML element a size, set the background to the size of the whole sheet, and move the artwork left. Use this beside a visible label, such as <span class="folder-tile" aria-hidden="true"></span> Files.
.folder-tile {
display: inline-block;
width: 24px;
height: 24px;
background: url("strip.svg") no-repeat;
background-size: 96px 24px;
background-position: -24px 0;
}
For a 36 px button icon, make the box 36 × 36, the background 144 × 36, and the folder offset −36 px. Close is three positions from the start, so its offset is −108 px. If changing the size reveals a sliver of the next icon, check all three measurements. For a sheet with several rows, apply the same calculation vertically.
Draw the same icon at any size with a symbol ID
Open icons.svg in a text editor. Each toolbar icon has an ID, a viewBox, and artwork. The file also holds a folder body that two icons reuse. The order of the definitions has no bearing on the order of the buttons.
To make a symbol by hand, take the drawing from a standalone SVG, wrap it in <symbol>, and carry over its drawing area. Keep inherited paint such as fill="none" and any gradients or clip paths the artwork references. Give internal resources unique IDs across the resulting file. Here is a complete one-icon sprite you can save as one.svg.
<svg xmlns="http://www.w3.org/2000/svg">
<symbol id="icon-close" viewBox="0 0 24 24">
<path d="m6 6 12 12M18 6 6 18" fill="none" stroke="currentColor"
stroke-width="2.5" stroke-linecap="round"/>
</symbol>
</svg>
Open that file by itself and the browser shows an empty page. The symbol defines a drawing. A <use> element creates a visible instance. Put this in an HTML page beside one.svg:
<button type="button" aria-label="Close dialog">
<svg width="24" height="24" aria-hidden="true">
<use href="one.svg#icon-close"></use>
</svg>
</button>
The filename locates the document and the fragment names the symbol. The outer width and height reserve space in the page. The four viewBox numbers give the left edge, top edge, width, and height of the source drawing. This icon therefore scales from 24 to 36 px without any offset math. Legacy files may spell the reference xlink:href. Use href in new examples.
Embed a small sprite directly in the page
Place the definitions once in the document and drop the filename from the reference. Give the library a zero-size box so it consumes no layout space. Prefix its IDs if the page contains other inline SVGs.
<svg width="0" height="0" aria-hidden="true" style="position:absolute">
<symbol id="toolbar-search" viewBox="0 0 24 24">
<g fill="none" stroke="currentColor" stroke-width="2.25">
<circle cx="10" cy="10" r="6"/>
<path d="m14.5 14.5 6 6" stroke-linecap="round"/>
</g>
</symbol>
</svg>
<button type="button">
<svg width="20" height="20" aria-hidden="true"><use href="#toolbar-search"></use></svg>
Search
</button>
Give the same folder two color schemes
The workshop's Search icon has one ink color. Its strokes use currentColor, so changing the button's text color also changes the magnifying glass. Folder has two paints: the paper and its outline. Suppose your inbox uses a teal folder and your archive uses an amber one. Both can reuse the same drawing.
To try it, copy the workshop's icons.svg to themed.svg. Find the path inside <symbol id="folder-body">. Change its fill to fill="var(--folder-paper, #46bfc1)" and its stroke to stroke="var(--folder-edge, #154858)". Keep its geometry and stroke width. Then place these two instances in an HTML page beside the file and serve the folder over HTTP.
<svg width="32" height="32" aria-hidden="true">
<use href="themed.svg#icon-folder"></use>
</svg> Inbox
<svg width="32" height="32" aria-hidden="true"
style="--folder-paper:#f6bf66; --folder-edge:#783b13">
<use href="themed.svg#icon-folder"></use>
</svg> Archive
Inbox uses the fallback colors in the file. Archive supplies its own values on the outer SVG. You can set those same properties in a dark-theme rule. A page selector like .toolbar svg path can't reach the path inside an external <use> instance, which is why the drawing itself reads the two properties.
Give the button an accessible name
A button with visible text already has a name. Hide its decorative SVG with aria-hidden="true". For an icon-only button, put the action name on the button, as in Close dialog above. For an icon that conveys information on its own, give the outer SVG role="img" and a contextual label such as aria-label="Folder synchronized". For an ordinary <img>, use alt.
Identify the right markup for an existing sprite
You may inherit a file where #folder names a region, a visible group, or a reusable definition. Open the source and find the element with that ID before choosing your HTML.
- Named view ·
views.svg - A
<view id="folder" viewBox="24 0 24 24"/>frames the second rectangle of the full drawing. Use<img src="views.svg#folder" width="24" height="24" alt="Folder">. Any artwork crossing that rectangle can appear in the image. For a sheet without named views, the fragmentstrip.svg#svgView(viewBox(24,0,24,24))specifies the rectangle directly. - CSS target stack ·
stack.svg - The drawings occupy the same space. Inside the SVG,
.layer { display: none }hides them and.layer:target { display: inline }reveals the group selected by the URL. Use<img src="stack.svg#folder" width="24" height="24" alt="Folder">or reference that URL as a CSS background. With no fragment, this particular file shows an empty canvas. - Named definitions ·
<defs> - Some libraries store a named
<g>or nested<svg>inside<defs>. Reference the entry with<use>. A group has no viewport of its own. If its artwork was drawn on a 24-unit grid, provide the correspondingviewBox="0 0 24 24"on the consuming SVG. A nested SVG can supply its own viewport.
Compare four ways to display the same icon
Select Folder, then switch from 24 to 36 px. Watch the offset beneath the first icon and the fragment names beneath the other three. All four cells render real SVG files.
Turn four SVG files into one sprite in IconVectors
Extract the example pack. The individual folder contains four ordinary SVGs. Open that folder in Icon Explorer, select the four files, and choose Explorer → Create SVG Sprite…. You can also find the command in the selection's context menu.
123
- 1Name the new file.
- 2Check the four filenames and sizes.
- 3Choose Create Sprite.
Enter toolbar.svg and choose Create Sprite. Use a fresh filename. IconVectors saves it in the current folder and opens it in the editor. Each input becomes one symbol with its own viewport. The individual SVG files stay available for other projects. If you prefer to draw the set yourself, File → New Sprite… lets you choose default dimensions and an initial number of empty icons.
123
- 1Select an entry in the thumbnail strip.
- 2Edit it on the canvas.
- 3Check the result in Preview.
Click a thumbnail, make a canvas edit, then switch thumbnails. One Save writes the whole collection, including edits made before you switched. Use Sprite → Export Icons… when you need separate SVG or PNG files. Press F3 and compare the SVG Sprite tab, which contains the complete file, with the SVG tab for the selected icon.
Watch the sprite editing walkthrough to see both source views, follow a color change to the Check icon, and see how to reorder and export icons from the sprite.
Select an entry and choose Sprite → Copy SVG Usage Code. Paste the snippet into your page and adjust the path relative to the HTML file. This also gives you the actual generated ID. The hand-authored icons.svg in the workshop has its own IDs and demonstrates a shared definition.
Build the toolbar from four SVGs with an MCP client
If you already have the four files, you can ask a local AI client to assemble them. Its Model Context Protocol (MCP) connection lets it give the filenames to the running IconVectors editor. Save any open edits first, since the new sprite opens in the editor when the operation succeeds.
- Connect to the editor. Start IconVectors 2.30 on Windows. In your client, connect the matching IconVectors MCP companion with the Full tool profile. Ask the client to run
app_ping. A successful reply confirms that it can reach the desktop app. For the connection steps, see the MCP client setup guides. - Choose a new output file. Extract the workshop ZIP. Locate the folder that contains
individualanddemo.html. The prompt below assumes that folder isC:/work/sprite-workshop. Substitute its actual absolute path on your computer.
Use IconVectors to build a sprite from search.svg, folder.svg, folder-checked.svg and close.svg, in that order. The files are in C:/work/sprite-workshop/individual. Save the new sprite as C:/work/sprite-workshop/toolbar-mcp.svg. Inspect it and tell me the four symbol IDs so I can use them in HTML.
The client calls sprite_create with the four absolute filenames in its paths array and the new filename in output_path. You can also select your files in Icon Explorer and ask the client to build from that selection. In that case it passes use_explorer_selection: true in place of paths. To review a sprite before writing it to disk, leave out output_path and save it from the editor when you're ready.
Check the result. Ask the client to run sprite_inspect and read the entry_id for each entry. With these files you'll get search, folder, folder-checked and close. In an HTML page beside the new sprite, <use href="toolbar-mcp.svg#folder-checked"></use> selects Checked Folder. The icon- prefix used in the workshop's hand-authored icons.svg belongs to that file.
Build the four-icon sprite from PowerShell
Use the IconVectors CLI when you want to rebuild a toolbar from the same source files. With an active license or trial for IconVectors 2.30 on Windows, open PowerShell in a freshly extracted workshop folder, beside demo.html. The first command sets the default install path. Adjust it if you installed IconVectors elsewhere.
$cli = "$env:ProgramFiles\Axialis\IconVectors\IconVectorsCli.exe"
& $cli sprite create --input individual/search.svg `
--new-id icon-search --output step-1.svg
& $cli sprite add --input step-1.svg --svg-file individual/folder.svg `
--new-id icon-folder --output step-2.svg
& $cli sprite add --input step-2.svg --svg-file individual/folder-checked.svg `
--new-id icon-folder-checked --output step-3.svg
& $cli sprite add --input step-3.svg --svg-file individual/close.svg `
--new-id icon-close --output toolbar.svg
& $cli sprite list --input toolbar.svg
sprite create wraps Search in the first symbol. Each sprite add reads the preceding sprite, imports one SVG, and writes the complete collection to a new file. That leaves your four originals and the workshop's supplied icons.svg intact. For another build in the same folder, add --overwrite to the four commands that write those outputs.
The final list should show icon-search, icon-folder, icon-folder-checked, and icon-close. The file to ship is toolbar.svg. For example, a button beside that file can draw the checked folder with <use href="toolbar.svg#icon-folder-checked"></use> inside its SVG.
Change one icon or update every icon that shares its shape
Open the supplied icons.svg. Its four toolbar icons appear alongside a fifth entry, folder-body. Both folder icons reference this definition. The checkmark is a separate path owned by Checked Folder. Importing four standalone files in the previous exercise creates individual symbols. Here, the shared folder body is explicitly defined in the example source.
- Try a local edit. Select Checked Folder in the strip. Select the checkmark on the canvas or in Layers and change its stroke color. Switch to Folder to compare. For a clean starting point, undo that edit.
- Try a shared edit. Select folder-body, then Sprite → Edit Shared Symbol…. Read the affected-icon list and choose Yes. Select the turquoise body and change its fill to orange.
- Check the result. Choose Finish Shared Symbol Editing, then select each folder thumbnail. Both now have the orange body. Search and Close have their own geometry. Save the workshop copy and reload
demo.html. Select each folder in turn. Only the Symbol instance cell reads the file you just saved.
12
- 1Read the affected-icon list.
- 2Choose Yes to start editing the shared body.
Rename Icon changes a display name. Change SVG ID changes the address used by <use>. After changing a public ID, update references in your HTML, CSS, or components. For imported views with overlapping artwork or complex CSS, the editor may protect drawing operations. Inspect the preview and source before deciding whether to export a standalone copy.
Migrate a legacy toolbar one button at a time
- Open
strip.svg. IconVectors recognizes the proportions and offers a square grid. To specify a grid explicitly, choose File → Open Legacy SVG Sprite… and select the sheet. - Enter 24 for both tile dimensions. The sheet is 96 units wide, so four complete tiles fit in one row. For a multirow sheet, tiles are read left to right, then top to bottom. Trim any gutters or irregular spacing in a working copy before using a regular grid.
- Choose Open as Legacy Sprite in the detected-sheet dialog. Inspect all four thumbnails and use Save As to write
toolbar-symbols.svg. Keepstrip.svgat its existing URL while any page still uses background offsets. - Select the second thumbnail. Give it the public ID
icon-folder, or copy its generated ID. Replace one CSS tile with the corresponding SVG reference below. Check it at 24 and 36 px before replacing the remaining tiles.
123
- 1Check the sheet dimensions.
- 2Set the tile width and height.
- 3Open the four tiles as a sprite.
<svg width="36" height="36" aria-hidden="true">
<use href="toolbar-symbols.svg#icon-folder"></use>
</svg>
Choose how the browser loads your toolbar
Where will people see these icons? A Search button in every page header has a different loading pattern from a set of drawing tools that appears only when someone opens an editor.
- The toolbar appears on several pages.
- Serve one external
icons.svgfrom the same origin as the pages. Search and Folder use different fragments of the same URL. The first page downloads the file, and later pages can reuse it while the cached copy is fresh. - The icons belong to a single screen.
- Place the symbols once in that page's HTML and reference them with
href="#icon-search". The icons arrive with the page, without a separate SVG request. Every page that embeds those definitions carries their bytes in its HTML. - A large set belongs to an optional panel.
- Give the panel its own sprite and reference it when the panel opens. Readers who only use the header then download just the header icons. If your application inserts symbol definitions into the page at runtime, insert them once and make them available before showing controls that use their IDs.
To check the trade-off on your own site, open the browser's Network panel with caching enabled. Start with an empty cache, visit a page showing Search, then follow a link to another page with the same toolbar. Compare the sprite's transferred bytes on the two visits. Also try a page that uses only Close: an external sprite still delivers the entire file.
Use one React component for all four symbols in Vite
In a Vite React project, copy the workshop's icons.svg to public/icons.svg. Vite copies that file into the built site. Save the code below as src/SearchButton.jsx. In src/App.jsx, add import SearchButton from './SearchButton.jsx'; and render <SearchButton /> where you want the button to appear.
const spriteURL = import.meta.env.BASE_URL + 'icons.svg';
function ToolbarIcon({ name }) {
return (
<svg width="20" height="20" aria-hidden="true">
<use href={spriteURL + '#icon-' + name} />
</svg>
);
}
export default function SearchButton() {
return <button type="button"><ToolbarIcon name="search" /> Search</button>;
}
For an app hosted at /workbench/ with Vite's base set to that path, Search references /workbench/icons.svg#icon-search. Try name="folder-checked" and change the visible button label to match. The component selects a drawing at render time. Removing a button from the app leaves all four symbols in the static SVG file. If you need to animate the actual paths of one icon from React, that drawing can instead live directly in its own component.
Keep the buttons working after optimization and updates
When you optimize the artwork, treat each public symbol ID as part of your HTML. An optimizer reading only icons.svg can't see that a button on another page asks for #icon-folder-checked. Configure ID cleanup to preserve the four public IDs. Keep each symbol's viewBox so it still scales in its button.
Internal IDs have a different job. Both folder icons reference #folder-body inside the file. If you rename it, update both references together. When importing icons that each contain a gradient named paint0, give each distinct gradient its own ID and update its matching url(#...). Otherwise the second icon can silently acquire the first one's colors. Test the optimized file in the toolbar at two sizes and in both themes; opening the SVG on its own won't show its symbols.
Keep the inputs you actually edit in source control. For the PowerShell build, those are the four individual SVGs and the script. For a sprite whose shared folder body you edit directly, the sprite itself is the source. If you serve a release with a long cache lifetime, publish the revised file under a new name, such as icons.v2.svg, then point the updated pages at it. Keep the old URL available while older pages still reference it.
Fix blank icons, clipped edges, and stale artwork
- The symbol is blank.
- Check the request in DevTools, then look for the exact, case-sensitive fragment ID in the returned SVG. For an external
<use>, serve the file from the page's origin (same scheme, host, and port). A separate CDN hostname is a different origin, even when its URL opens in a tab. Test the ZIP through a local HTTP server so the page and sprite share an origin. - The wrong tile appears or an edge is clipped.
- For a CSS sheet, compare the rendered background size and offset with the cell size. For a symbol, inspect all four
viewBoxnumbers, including a nonzero origin. A stroke can extend beyond the path's coordinates. - The icon ignores the theme or picks up the wrong gradient.
- Inspect fixed fills and strokes in the symbol. For themed artwork, set the relevant paint to
currentColoror an explicit CSS variable. For gradients and clips, check eachurl(#id)after combining files. Repeated IDs can resolve to the wrong resource. - The browser still shows the old drawing.
- Verify the page requests the file you edited. Look for an output directory regenerated during the build and inspect the response with the browser cache disabled. Use a versioned filename or a build-generated hash when shipping a new sprite with long-lived cache headers.