CSS Image Sprites

Beginner
7 min read
Updated: Nov 2026
3 examples
One image file

Definition and Usage

A CSS image sprite is one picture that holds several graphics. This tutorial uses /images/browser-image-sprite.png: Chrome, Firefox, Safari, Edge, Internet Explorer, and Opera in a single file.

The element is a small window. width and height set that window. background-image loads the whole sheet. background-position slides the sheet until the logo you want sits in the window. background-repeat: no-repeat keeps the other logos from tiling into view.

Negative position moves the sheet left and up.

With a 48px window and the sheet scaled to 288×144, background-position: -4px -46px shows Chrome. -51px -48px shows Firefox.

CSS Syntax

One shared rule for the sheet. A second rule picks the logo:

CSS
.icon {
  width: 48px;
  height: 48px;
  display: inline-block;
  background-image: url("/images/browser-image-sprite.png");
  background-repeat: no-repeat;
  background-size: 288px 144px;
}

.chrome { background-position: -4px -46px; }
.firefox { background-position: -51px -48px; }
.safari { background-position: -97px -47px; }

Core Ideas

The sheet below is the file every example slides.

The same browser sprite: six logos in one row
IdeaExampleRemember
The filebrowser-image-sprite.pngSix logos, one download
The windowwidth: 48px; height: 48pxOnly this square is visible
The scalebackground-size: 288px 144pxShrinks the sheet to fit six 48px slots
Chrome-4px -46pxFirst logo in the row
Firefox-51px -48pxSlide further left
Safari-97px -47pxThird logo in the row

CSS Examples

Each window reads /images/browser-image-sprite.png. View Output shows the slice. Try It Yourself opens the same example in the editor.

Example 1 — Show the first logo

A 48px window and -4px -46px land on Chrome.

CSS
.chrome {
  width: 48px;
  height: 48px;
  background: url("/images/browser-image-sprite.png")
    no-repeat -4px -46px;
  background-size: 288px 144px;
}
Try It Yourself

How It Works

  1. url(...) loads the whole browser sheet, not a separate Chrome file.
  2. 48px by 48px is the window. The rest of the sheet stays outside it.
  3. -4px -46px shifts the sheet so the Chrome logo fills that window.

Example 2 — Three logos, one file

Chrome, Firefox, and Safari share the image. Each class only changes background-position.

CSS
.chrome  { background-position: -4px -46px; }
.firefox { background-position: -51px -48px; }
.safari  { background-position: -97px -47px; }
Try It Yourself

How It Works

  1. The same url is already on .icon. These rules do not load three files.
  2. A larger negative x moves the sheet left, which reveals the next logo.
  3. The y values stay near -46px because the logos share one row.

Example 3 — Swap the logo on hover

The window starts on Chrome. Hover moves background-position to the Firefox slice.

CSS
.chrome {
  background-position: -4px -46px;
}

.chrome:hover {
  background-position: -51px -48px;
}
Try It Yourself

How It Works

  1. At rest the position is Chrome, -4px -46px.
  2. :hover changes only the position, to -51px -48px.
  3. The image file stays browser-image-sprite.png. The pointer just slides the sheet.

Frequently Asked Questions

A sprite is one image file that holds several pictures. This page uses /images/browser-image-sprite.png, a single sheet of browser logos. The element’s width and height are a window. background-position slides the sheet so only one logo shows.
background-image loads the sheet. background-repeat: no-repeat stops the logos from tiling. background-size scales the sheet. width and height set the window. background-position chooses the logo. On this sheet, -4px -46px shows Chrome when the window is 48px and the sheet is scaled to 288px by 144px.
The browser downloads the sheet once and reuses it for every icon. That is fewer image requests than a separate file per logo. With HTTP/2, several small files can also be fine. The sprite is still the way to show a chosen slice of one picture.
Keep the same background-image. On :hover, change only background-position. The Chrome window on this page moves to the Firefox slice when the pointer is over it.
The window and the position have to match the sheet. A 48px box with the wrong background-position shows a sliver of the next logo or empty space from the sheet.

Next: Grid Layout

Place items in rows and columns with display: grid.

Grid layout tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful