CSS image sprites combine many small images into one file. You show individual icons with background-image and background-position — reducing HTTP requests and keeping UI graphics consistent.
01
Sprite sheet
One PNG file.
02
Position
Show a slice.
03
Size
Icon window.
04
Fewer requests
Faster loads.
05
Real sprite
Browser logos.
06
4 try-it
Live editors.
Fundamentals
Introduction
CSS image sprites are a technique used to optimize web performance by combining multiple images into a single image file. This reduces the number of HTTP requests the browser makes, which can improve load times — especially on pages with many small icons.
Sprites are commonly used for icons, buttons, and other small graphics that appear repeatedly across a site. Instead of loading ten separate PNG files, you load one sprite and use CSS to reveal the correct icon.
What Are Image Sprites?
An image sprite is a single image file that contains multiple smaller images arranged in a grid or row. CSS controls which portion is visible by setting the element’s size and shifting the background with background-position.
Think of it like a window sliding over a larger photograph — the element’s width and height are the window size; background-position moves the photo behind the window.
💡
Beginner Tip
On this page we use the real /images/browser-image-sprite.png file (1774×887 px) with six browser logos. The same technique works for any icon set.
Why Use Image Sprites?
Reduced HTTP requests — One file download instead of dozens of tiny icon requests.
Improved performance — Fewer round trips can mean faster first paint on HTTP/1.1 connections.
Consistent design — All icons come from the same source file, keeping visual style aligned.
Cache efficiency — Browsers cache one sprite; every icon on the page benefits.
Preparation
How to Create an Image Sprite
Combine individual images into one file using an image editor (Figma, Photoshop, GIMP) or an online sprite generator. Icons are usually aligned horizontally or vertically with consistent spacing.
Here is a simplified diagram of a horizontal sprite with three icons:
Our browser sprite arranges six logos in one row inside a 1774×887 pixel PNG:
The full sprite sheet — CSS reveals one logo at a time.
Foundation
📝 Implementing Image Sprites in CSS
Use background-image for the sprite file, background-position to show the correct slice, and fixed width / height for the visible icon area.
sprite-base.css
/* Shared sprite setup */.icon{--size:48px;width:var(--size);height:var(--size);background-image:url("/images/browser-image-sprite.png");background-repeat:no-repeat;display:inline-block;}/* Chrome — shift background to logo center */.icon-chrome{background-position:-4px -46px;}
Key properties
Property
Role in sprites
background-image
Loads the combined sprite file
background-position
Shifts which part of the sprite is visible
background-size
Scales the sprite sheet (needed for responsive icons)
width / height
Defines the visible “window” size
background-repeat
Usually no-repeat for icons
Cheat Sheet
⚡ Quick Reference
Step
Action
1. Create sprite
Combine icons into one PNG (or SVG)
2. Base class
Set background-image, size, no-repeat
3. Per-icon class
Override background-position only
4. Measure offsets
Note each icon’s x/y position in the sprite
5. Test in DevTools
Tweak position values until the correct icon shows
Performance
🖼 Optimizing Image Sprites
When creating sprites, follow these practices:
Compress the sprite — Use tools like TinyPNG or Squoosh to shrink file size without visible quality loss.
Align images correctly — Consistent icon dimensions make background-position math predictable.
Choose the right format — PNG for icons with transparency; SVG for scalable single-file icons in modern projects.
Document coordinates — Keep a comment or map of each icon’s offset for maintainability.
Limit sprite size — Very large sprites can slow the initial download; split into themed sheets if needed.
Preview
👀 Live Preview
Three browser logos from the same sprite file — only background-position changes:
Chrome
Firefox
Safari
Hands-On
Examples Gallery
Four examples using /images/browser-image-sprite.png — from a single icon to a reusable sprite pattern for lists and toolbars.
🖼 Sprite Basics
Start with one icon, then show several from the same file.
Example 1 — Single Icon from Sprite
Display the Chrome logo by positioning the background over the sprite sheet.
Bottom line: CSS sprites are a universal, production-safe technique. Modern alternatives include SVG sprites and icon components, but background sprites remain fully supported.
Wrap Up
🎉 Conclusion
CSS image sprites are a powerful technique for optimizing web performance by reducing HTTP requests. While HTTP/2 and SVG icons have reduced their necessity, sprites remain excellent for teaching background CSS and maintaining legacy icon sets.
By following best practices — compressing assets, documenting coordinates, and avoiding overly complex sheets — you can use sprites to enhance both speed and visual consistency.
Combine, position, display — fewer requests, same icons.
5
Core concepts
1px01
One file
Many icons.
Asset
pos02
Position
Shift view.
CSS
wh03
Size
Window.
Box
req04
Fewer HTTP
Faster.
Perf
a11y05
Labels
aria.
A11y
❓ Frequently Asked Questions
An image sprite is a single image file that contains multiple smaller images. CSS background-image and background-position show only the slice you need, so the browser downloads one file instead of many.
They reduced HTTP requests. Each separate image file used to require its own network round trip. Combining icons into one sprite improved load times on HTTP/1.1 sites.
Less critical with HTTP/2 multiplexing and SVG icons, but sprites still work well for repeated UI icons, legacy support, and teaching how background-position works.
background-image sets the sprite sheet, background-position shifts to the correct icon, background-size scales the sheet, and width/height define the visible window.
Incorrect background-position values. Even a few pixels off shows the wrong part of the image. Always match element size to the icon size in the sprite.