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.
Syntax
CSS Syntax
One shared rule for the sheet. A second rule picks the logo:
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.