How to make a CSS sprite sheet from Figma icons

Make a CSS sprite sheet from Figma icons: how background-position picks each icon, when sprites still beat SVG, and the free UIXport tool with its limits.

By UIXport team10 min read
On this page

Key takeaways

  • A CSS sprite is one image that holds many icons. Each element shows its own icon by setting its size and shifting the image with background-position.
  • Sprites still make sense for small raster images, older themes built on background-image icons and simple game or UI skins. For sharp single-colour UI icons, SVG or an icon font is usually the better choice.
  • UIXport's free CSS Sprite tool, in the Dev tools tab, packs your selected Figma layers into spritesheet.png and spritesheet.css, with an .ex-sprite base class and one .ex-sprite-{name} class per icon.
  • Generate Sprite Sheet is free with no cap, whatever the icon count. Changing Cell columns (2 to 12) or Cell padding (0 to 32 px) afterwards re-packs the sheet without exporting again.
  • The sheet is PNG at 1x only, with no retina, SCSS, JSON or SVG sprite, so draw icons at the size they will appear and keep them the same size.

Short answer: A CSS sprite sheet is one image that holds many icons, and CSS shows one at a time by giving an element the icon's size and shifting the image behind it with background-position. To make one from Figma, select your icons, open UIXport's Dev tools tab, choose CSS Sprite and click Generate Sprite Sheet. You get a PNG and a CSS file with a class for every icon.

Say you're updating an older WordPress theme. Its stylesheet already shows every social icon as a background image, there's no build step, and the client wants six new icons that match. You could export six PNGs and measure offsets by hand. Or you could hand over one image and one CSS file with the offsets already worked out.

That second option is a sprite sheet. One catch: UIXport makes a new sheet with its own .ex-sprite classes. It won't append icons to the theme's existing sprite image, so rebuild the whole set from Figma or rename the generated classes to match the theme.

What is a CSS sprite?#

A CSS sprite is a single image file that holds many small images, usually icons, laid out in a grid. Each element on the page shows only its own slice of that image, using CSS background properties.

Game developers know the same idea as a sprite sheet or texture atlas. On the web, MDN's guide to implementing image sprites in CSS gives the reason: one image to fetch instead of many.

A sprite sheet comes in two parts:

  • The image. One PNG with every icon, spaced so none touch.
  • The CSS. A rule per icon that sets the element's size and moves the image so the right icon shows through.

Are CSS sprites still used, and when do they make sense?#

Yes, but they're no longer the default. HTTP/2 changed the maths: MDN's sprite guide now notes that with HTTP/2 it "may in fact be more bandwidth-friendly to use multiple small requests." Our take: for single-colour UI icons, SVG is usually the better choice, because it stays sharp and takes its colour from CSS.

A sprite still earns its place in a few situations:

Situation Sprite sheet? Why
Many small raster images: flags, badges, swatches Yes They aren't vectors, so SVG doesn't help
An older theme or CMS built on background-image icons Yes Adding to the sprite keeps one pattern instead of two
Raster art for a simple game or themed UI Often Buttons, tiles and states fit a grid
A static site with no build step Often All you ship is a stylesheet and an image
Single-colour UI icons that change colour on hover No SVG or an icon font takes its colour from CSS
Icons that must stay sharp on high-density screens Not as a 1x sheet SVG or an icon font stays sharp at any density

For the vector options, our comparison of icon font vs SVG sprite vs inline SVG covers accessibility, colour and caching.

How does background-position pick an icon from a sprite?#

The element is a small window, and background-position slides the big image behind it. Negative values move the image left and up, so the icon you want lines up with the window.

Per MDN, background-position sets where a background image starts, top-left by default. With two lengths, the first is horizontal and the second vertical.

A worked example: twelve 24×24 icons, 8 px of padding around each, four columns.

  • Each cell is 8 + 24 + 8 = 40 px square.
  • The sheet is 4 × 40 = 160 px wide and 3 × 40 = 120 px tall.
  • The first icon starts 8 px in from the top and the left, so its offset is -8px -8px.
  • The second icon is one cell to the right: -48px -8px.
  • The fifth icon starts the second row: -8px -48px.

In CSS that looks like this:

css
.icon {
  background-image: url("sprite.png");
  background-repeat: no-repeat;
  display: inline-block;
  width: 24px;
  height: 24px;
}
.icon-home   { background-position: -8px -8px; }
.icon-search { background-position: -48px -8px; }
.icon-bell   { background-position: -8px -48px; }

Width and height matter as much as the offset. An element bigger than its icon shows some of the padding, and a much bigger one shows the edge of the next icon. Padding is your margin for error.

How should you prepare Figma icons for a sprite sheet?#

Give every icon the same frame size, at the size it will appear on the page, with no background fill and a clear, unique name.

  • Use one frame size. Put each icon in a same-size frame, such as 24×24. Every cell in the sheet is the largest icon's size plus padding, so a single 48 px illustration in a set of 24 px icons makes every cell 64 px and leaves most of the sheet empty. If you have two sizes, make two sheets: select the other icons and click Re-Generate. Every run saves the same file names and .ex-sprite base class, so rename the second sheet's PNG, CSS and base class (say .ex-sprite-lg, with its url() updated), and give its layers different names, or the two sheets will overwrite each other.
  • Draw at the display size. The sheet is exported at 1x, so a 24×24 frame becomes a 24×24 icon in the PNG and a 24×24 element in the CSS.
  • Remove the frame fill. If the frame has a fill, it is exported too, so a white fill becomes a white square behind the icon. Hide or delete it. Our guide to transparent PNG exports from Figma explains where backgrounds sneak in.
  • Name each layer for the class you want. Class names come from layer names, case kept, with spaces, slashes and other symbols turned into underscores: a component named icon/arrow-left gives .ex-sprite-icon_arrow-left. Name layers in lowercase with hyphens, such as arrow-left, for a clean .ex-sprite-arrow-left. Keep every name unique so no two icons share a class.

Steps to build a CSS sprite sheet in Figma with UIXport#

UIXport's CSS Sprite tool turns the layers you select into one PNG and one CSS file. It's on the Free plan, and everything happens inside the plugin, so your icons aren't uploaded anywhere.

  1. Select your icons. Select the icon frames on the canvas. Each selected layer becomes one cell. With nothing selected, the tool shows No Frames Selected.
  2. Open Dev tools. In UIXport, click the Dev tools tab. The panel is headed Developer handoff.
  3. Choose CSS Sprite. It's the first item under Tools and opens by default.
  4. Generate the sheet. Click Generate Sprite Sheet. While it shows Generating Sprite..., UIXport exports each layer and packs them into a grid.
  5. Adjust the grid. Under Grid settings, set Cell columns and Cell padding. The Live sprite preview updates straight away, and you can click it to zoom in.
  6. Download or copy. Click Download ZIP Bundle to save spritesheet-assets.zip. To paste the rules into an existing stylesheet, use Copy CSS under Sprite CSS Rules. If you change the selection, click Re-Generate before you download.

How do you choose cell columns and padding?#

Columns set the shape of the sheet, and padding sets the gap around each icon. The defaults, 4 columns and 8 px, suit most small icon sets.

Setting Range Default When to change it
Cell columns 2 to 12 4 To make the sheet wider or taller
Cell padding 0 to 32 px, in steps of 2 8 px Lower for a compact sheet, higher if you plan to scale the sheet

Columns make little difference to the browser. Rows follow from the icon count, so twelve icons at 4 columns give 3 rows.

Padding is added on every side of a cell, so neighbouring icons sit twice the padding apart: 16 px at the default. Use 0 only if every element will be exactly its icon's size. Go higher if you'll scale the sheet with background-size, because scaling can pull stray pixels from a neighbour into view.

What's in spritesheet-assets.zip?#

Two files: spritesheet.png, the packed image, and spritesheet.css, the rules that show each icon. Keep them in the same folder, because the CSS points to the PNG by file name, or edit the url() in .ex-sprite.

The CSS has one base class and one class per icon:

  • .ex-sprite sets the background image, turns off repeating, makes the element inline-block so an empty <span> takes up space, and aligns it to the middle of the text line.
  • .ex-sprite-{name} sets that icon's width, height and background-position.

With 24×24 icons named home and search at the default settings, the file looks roughly like this (trimmed):

css
.ex-sprite {
  background-image: url('spritesheet.png');
  background-repeat: no-repeat;
  display: inline-block;
  vertical-align: middle;
}

.ex-sprite-home {
  width: 24px;
  height: 24px;
  background-position: -8px -8px;
}

.ex-sprite-search {
  width: 24px;
  height: 24px;
  background-position: -48px -8px;
}

Each icon class uses that icon's own size, and the offsets already allow for smaller icons being centred in their cells.

How do you add a sprite icon to a page?#

Give an empty element both classes, the base class and the icon's class, then pair it with a text label.

html
<link rel="stylesheet" href="/assets/spritesheet.css">

<a href="/search" class="nav-link">
  <span class="ex-sprite ex-sprite-search" aria-hidden="true"></span>
  Search
</a>

MDN's background-image page explains that browsers give assistive technology no special information about background images, so a screen reader won't announce the icon. For an icon-only button, put visually hidden text inside the button so it still has a name.

To swap an icon on hover, copy the background-position from the other icon's class:

css
/* star-filled sits at -48px -8px in this sheet */
.fav:hover .ex-sprite-star {
  background-position: -48px -8px;
}

Both states live in the same image, so the hover icon is already loaded when the pointer arrives.

What are the limits, and what should you use instead?#

UIXport's sprite is a plain 1x PNG grid with CSS. That's the right shape for raster icons in a simple stylesheet, and the wrong one when you need sharp vector icons, a retina sheet or data for a build tool.

A 1x sheet looks soft on high-density screens, because each image pixel is spread across several screen pixels (see 1x, 2x and 3x exports).

You can work around it by hand. Draw the icons at twice their display size in Figma (48×48 frames for 24 px icons, with 16 px padding) and generate the sheet. Then edit the CSS: give .ex-sprite a background-size of half the PNG's pixel width and height, and halve every width, height and offset. It works, but you redo those edits every time you regenerate. For more than a handful of icons, one of these is less work:

You need Use From Figma with UIXport
Sharp single-colour icons, coloured with CSS Icon font Yes: Icon Font makes a TTF plus CSS
Sharp icons with several colours One SVG per icon, or inline SVG Yes: SVG export, cleaned with SVGO
One cached file of vector icons used with <use> SVG sprite No, use a plugin built for SVG sprites
A sheet with frame data for a game engine A texture atlas from your game's tooling No
A sharp PNG sprite A 2x sheet scaled with background-size Partly, with the CSS edits above

If an icon font fits, Figma icons to icon font walks through building one from the same selection.

Make your first sprite sheet#

Start small. Pick eight icons of the same size, generate a sheet and drop the two files into a test page before you commit a whole theme to it.

Install UIXport from Figma Community to try it.

Questions

Are CSS sprites still used?

Yes, but less than before. They still suit raster icons, older themes built on background images and simple browser games, while single-colour UI icons are usually better as SVG or an icon font.

How does background-position work in a CSS sprite?

The element works as a window the size of one icon, and background-position moves the sprite image behind it. Negative values shift the image left and up until the icon you want lines up with the window.

Can UIXport make a retina or 2x sprite sheet?

No. The CSS Sprite tool exports icons as PNG at 1x only, and there is no 2x sheet, SCSS, JSON or SVG sprite. You can draw icons at double size, then halve every width, height and offset in the CSS and set background-size to half the PNG's size, or use an icon font or SVG instead.

How many exports does a sprite sheet use?

None that count against a limit. CSS Sprite is on the Free plan with no cap, however many icons you select or how often you Re-Generate.

Why is there so much empty space in my sprite sheet?

Every cell is sized to the largest selected icon plus padding on both sides. If one icon is much bigger than the rest, put it in a separate sheet, and rename that sheet's files and .ex-sprite class so the two don't overwrite each other.

Where do the sprite class names come from?

From the Figma layer names, with spaces, slashes and other symbols turned into underscores. Rename the layers before you generate, and check spritesheet.css for the exact names.

Features in this post

Share this post

Share on XShare on LinkedIn

UIXport team

We build UIXport, the Figma plugin for exporting, compressing and delivering UI assets, at Sigma Studio.

About UIXport

Try it in Figma

Install the plugin from Figma Community. Free includes unlimited core exports and 10 Pro runs a month; Pro adds motion export, print-ready PDFs, AVIF and more.