Image guides

Pack an icon sheet and use the saved CSS

·

A sprite sheet stores several images in one PNG. Each icon needs its own rectangle or CSS class so it can be drawn from the right position.

Sprite Sheet Packer

Pack three icons using a 2-pixel gap

Click Load example to queue Flag, Marker and Dot. Leave the maximum width at 32 pixels and the gap at 2 pixels. Click Pack sprites. The resulting sheet is 26 × 22 pixels. The third sprite wraps to the next row.

Pack three icons using a 2-pixel gap
FileSizeUpper-left position
flag.png16 × 100, 0
marker.png8 × 1418, 0
dot.png6 × 60, 16

W3C Portable Network Graphics Third Edition

Display a single icon with its generated class

Select Download sprite ZIP. Place sprite.png and sprite.css in the same directory and load the stylesheet in your project. Use the icon and icon-02-marker classes together on an element to show only Marker.

The class sets an 8 × 14 pixel box and shifts the background left 18 pixels. The shared rule points to sprite.png next to the stylesheet.

W3C CSS Backgrounds and Borders Level 3, background positioning

Use the coordinate map for a game or other renderer

Open sprite-map.json and read each sprite’s x, y, width and height. The coordinates start at the sheet’s upper-left corner and can be passed as a source rectangle to a renderer.

When you change the gap or width, export a fresh sheet and matching coordinates together. The original decoded sprite sizes stay the same, while packing can move them to new positions.

W3C Portable Network Graphics Third EditionW3C CSS Backgrounds and Borders Level 3, background positioning

Common questions

Can I mix rectangular and square icons?

Yes. Each raster keeps its decoded dimensions. The longest icon on a given row determines the distance to the next row.

What happens if a source filename has spaces or symbols?

The class uses a safe normalized name and a source-order prefix. The JSON map records the original filename and generated class together.

Sources

Put it into practice.

Related guides