Image to Sprite Converter
Convert multiple images into a CSS sprite sheet with auto-generated CSS code. Supports retina @2x, custom padding, and bin-packing layout.
Drop PNG, JPG, GIF, or WebP images here
or click to browse · max 50 files · 10 MB each
Sprite Sheet Preview
Generated CSS
About
CSS sprite sheets reduce HTTP requests by combining multiple images into a single file. Each element references the combined image via background-position offsets. Incorrect offset calculations produce cropped or misaligned icons - a defect that compounds across responsive breakpoints and retina displays. This tool implements a shelf bin-packing algorithm to compute optimal placement, generating pixel-accurate CSS with width, height, and negative background-position values for every sprite. Retina output doubles the source canvas and emits a background-size declaration scaled to 50% of the physical sheet dimensions.
The packing algorithm sorts images by descending height and assigns them to horizontal shelves. This heuristic does not guarantee globally optimal area but typically achieves 85 - 95% fill rates for icon sets of similar aspect ratio. Padding between sprites prevents texture bleeding at fractional zoom levels. Note: input images must share a consistent visual language (size, padding) for the resulting sprite to be practical in production CSS. The tool processes everything client-side - no images leave the browser.
Formulas
Each sprite's CSS declaration is computed from its packed position on the composite canvas:
Where x and y are the top-left coordinates of the sprite within the sheet, in px.
The shelf packing algorithm determines placement:
Where shelfX is the current horizontal cursor, w is the image width, pad is the configured padding, and maxW is the maximum sheet width.
For retina output, the 2x sheet uses native pixel dimensions, while the CSS references logical dimensions:
Where sheetW and sheetH are the physical pixel dimensions of the 2x canvas.
The FNV-1a hash for cache-busting digest is computed over the raw RGBA pixel buffer:
Where the initial offset basis is 2166136261 and multiplication wraps at 232.
Reference Data
| Parameter | Default | Range | Description |
|---|---|---|---|
| Padding | 2px | 0 - 50px | Space between sprites to prevent bleed at sub-pixel rendering |
| CSS Class Prefix | icon | Any valid CSS ident | Base class for all sprites, e.g. .icon, .icon-name |
| Retina (@2x) | Off | On / Off | Generates a second sheet at double resolution with media query |
| Layout | Horizontal shelves | Horizontal / Vertical | Shelf packing direction |
| Output Format | PNG | PNG / WebP | Sprite sheet image format |
| Max Sprite Width | 2048px | 256 - 8192px | Maximum canvas width before wrapping to next shelf |
| Max Images | 50 | 1 - 50 | Browser memory constraint for canvas compositing |
| Max File Size | 10MB | Per image | Prevents excessive memory allocation on decode |
| Supported Formats | PNG, JPG, GIF, WebP | - | Raster formats decodable by browser Canvas |
| Filename Sanitization | Auto | - | Strips non-alphanumeric chars, lowercases for CSS class names |
| Bin Packing Algorithm | Shelf (NFDH) | - | Next Fit Decreasing Height - simple, fast, good average fill |
| Fill Efficiency (typical) | 85 - 95% | - | Depends on variance in image dimensions |
| background-size (retina) | 50% of 2x sheet | - | Ensures retina image renders at 1x logical size |
| Cache Busting | FNV-1a hash suffix | On / Off | Appends content hash to filename for CDN invalidation |
Frequently Asked Questions
.scss or .less file. To convert to a SASS mixin pattern, replace the base class background-image declaration with a mixin and @include it in each sprite class. The background-position values remain identical regardless of preprocessor - they are absolute pixel offsets.