CSS Sprite Generator
ImagesEverything runs locally in your browser — nothing is uploaded
Drop an image here, or click to choose
Or press Ctrl/⌘ + V to paste a screenshot
PNG / JPEG / WebP / GIF / BMP / AVIF · up to 30 MB each
Drop several small icons in and the tool packs them into one image, handing back each icon’s `background-position` — a single request for the whole set. Sites with many tiny icons still work this way. The packing uses the classic shelf algorithm: sort by height descending, place into the current shelf, start a new one when it does not fit, with the shelf height taken from its tallest item. The sort matters — without it a single tall image leaves a large hole in its shelf while shorter ones afterwards fail to fit. Two easy traps, stated up front: the gap is not only cosmetic — when you scale the whole sprite with `background-size`, bilinear interpolation samples neighbouring icons at the edges, which shows up as a strip of someone else’s colour; one or two transparent pixels break that path. And @2x images need every position and size halved in the CSS plus a `background-size` on the base class — miss either and the icons come out twice as large or misaligned.
Features
- Drop several images at once and get a single packed PNG sprite
- Generates each icon’s CSS: background-position plus width and height
- Three layouts: automatic and compact, one row, one column
- Adjustable gap, so neighbours do not bleed into each other when scaled
- @2x mode halves positions and sizes and writes background-size
- Class names derived from file names, sanitised into valid selectors
- Duplicate names get a suffix, so two icons never share one rule
- The CSS arrives as a separate text output — copy it or download it as .css
- Images are never uploaded; works offline
How to use
- Drop several icons onto the dashed area (or pick multiple files)
- Choose the layout and gap; tick @2x if the icons are 2× assets
- Download the packed PNG and copy the generated CSS
- Put the PNG in your project and point the url() at its real path
FAQ
- Do sprites still make sense?
- It depends. HTTP/2 and HTTP/3 made extra requests much cheaper, and SVG icons can be inlined as a single `<symbol>` set. But when there are many tiny bitmap icons (game UI, older admin panels, toolbars), sprites remain the simplest win: one request instead of dozens, with no change to your build. Conversely, with a dozen icons, plain SVG is clearer and far easier to recolour.
- Why keep a gap of 1–2px?
- Because scaling the whole sprite with `background-size` (the usual way to support high-density screens) makes the browser interpolate: sampling an icon’s edge pixel pulls in the neighbouring icon too, which appears as a strip of the wrong colour. One or two fully transparent pixels break that path. At 1× scale, zero is fine.
- What does @2x mode actually do?
- It treats the inputs as 2× assets: every icon’s `width` / `height` and `background-position` is halved in the CSS, and the base class gets `background-size` set to half the sprite’s dimensions. Icons then render at logical size on normal screens and at full pixel density on high-DPI ones. Getting the box wrong shows up as icons twice as large (no halving) or as only a small top-left fragment (missing background-size).
- How are the class names decided?
- The file name loses its extension and is sanitised down to lowercase letters, digits and hyphens, then your prefix is added. Sanitising is not optional: class names go into CSS and HTML, and CJK characters, spaces or quotes in a file name would break the selector or escape an attribute. A name with nothing usable left (an all-CJK file name, say) becomes icon-1 by position, and two icons colliding on a name get a numeric suffix (-2, -3) so their rules do not overwrite each other.
Related tools
Image Stitcher
ImagesStitch images into a tall strip, side by side, or a grid. Adjust the gap, corners and background; uniform sizing never upscales. Runs in your browser.
App Icon Generator
ImagesGenerate the full iOS AppIcon set, Android mipmaps and adaptive icons, and a macOS .icns from one image. Adjustable corners and padding, flattened for iOS.
Image Compressor
ImagesCompress an image to a target size (say under 200 KB): the tool binary-searches for the highest quality that fits. Quality steps and size limits too.
Image Converter
ImagesConvert between PNG, JPEG, WebP, AVIF, BMP and TIFF, with adjustable quality and size. JPEG output lays a background, so transparency never turns black.
Image Slicer
ImagesSlice an image into a grid for nine-tile posts or a tall image. Six grid shapes, per-tile padding, and names padded for posting in order.
Image Watermark
ImagesAdd a text watermark to a photo: nine positions plus tiling, with the size scaled to the image so it looks the same at any resolution.