The Mystery Of CSS Sprites: Techniques, Tools And Tutorials


CSS Sprites are not new. In fact, they are a rather well-established technique and have managed to become common practice in Web development. Of course, CSS sprites are not always necessary, but in some situation they can bring significant advantages and improvements – particularly if you want to reduce your server load. And if you haven’t heard of CSS sprites before, now is probably a good time to learn what they are, how they work and what tools can help you create and use the technique in your projects.

What Are CSS Sprites?

The term “sprite” (similar to “spirit,” “goblin,” or “elf”) has its origins in computer graphics, in which it described a graphic object blended with a 2-D or 3-D scene through graphics hardware. Because the complexity of video games has continually increased, there was a need for smart techniques that could deal with detailed graphic objects while keeping game-play flowing. One of the techniques developed saw sprites being plugged into a master grid (see the image below), then later pulled out as needed by code that mapped the position of each individual graphic and selectively painted it on the screen.

Sprites were displayed over a static or dynamic background image, and the positioning of the sprite was controlled simply by the hardware controllers. The term was coined because the sprites seemed to “haunt” the display and didn’t really exist in the graphic memory.

The Pokemon Sprite Sheet, consisting of over 1000 graphic objects. Found here2. You can click on the image for the larger version (thanks, Ryan!).

Time passed, and at the beginning of the 2000s, when progressive Web designers started to seek alternatives to JavaScript-based rollover menus (with onMouseOver and onMouseOut effects), sprites saw a renaissance in Web development. With CSS, the simple implementation of sprites was possible, and it was much easier and clearer than its JavaScript-based predecessor.

In 2004, Dave Shea suggested3 a simple CSS-based approach to CSS sprites based on the practice established by those legendary video games. In this case, multiple images used throughout a website would be combined into the so-called “master image.” To display a single image from the master image, one would use the background-position property in CSS, defining the exact position of the image to be displayed. Any hover, active or focus effects would be implemented using the simple definition of the background-position property for the displayed element.

When the page is loaded, it would not load single images one by one (nor hover-state images per request), but would rather load the whole master image at once. It may not sound like a significant improvement, but it actually was: the main disadvantage of the onMouse effects is that JavaScript-based hover effects require two HTTP requests for each image, which takes time and creates that unpleasant “flickering” of images. Because the master image is loaded with the whole page only once with CSS sprites, no additional HTTP requests are needed for hover, active or focus effects (because the image is already loaded), and no “flickering” effect occurs.

Consequence: CSS sprites reduce HTTP requests and the loading time of pages. This is the main reason why CSS sprites are often used on websites with heavy traffic, where millions of page impressions would need “only” a tiny fraction of what could otherwise be 30,000,000. Hence, CSS sprites are commonly used, particularly for navigation (such as for hover effects), icons and buttons.

Where Are CSS Sprites Used?

CSS sprites can be used in various settings. Large websites can combine multiple single images in a meaningful manner, creating clearly separated “chunks” of the master images – the purpose being to keep the design maintainable and easy to update. The large empty space between the images is often used to make sure that the text resizing in browser doesn’t cause side effects such the display of multiple images in the background. In fact, sprites usually work well in a pixel-based design, but they are hard to use in elastic (em-based) designs due to the restricted background-position-property. Essentially, the structure that sprites take depends on the trade-off between maintainability and reduced server load; thus, it varies depending on the project you are working on.

Here are some inspiring (and not so inspiring) examples:

Xing uses various icons and buttons, as well as its logo, in the sprite.


Large, shiny and compact CSS sprites on Amazon.


Apple uses CSS sprites for various states of its main navigation menu.


YouTube takes a vertical approach to its buttons and icons. The whole sprite is 2800 pixels in height!


CNN uses a modest CSS sprite with its social icons.


Digg has quite an esoteric sprite, with small arrows and brackets. The large empty space between the images is used to make sure that text resizing doesn’t display multiple images as the background image. You can explicitely define width and height in pixels, so that this problem does not occur – however, in this case the resized text will never break out of the defined box, thus possibly making the text unreadable. Consequently, you must be cautious when using spriting for buttons with variable text labels. For those buttons, you should define font size in pixels also. Or just use the large empty space in the sprite (thanks, daftie!).


Yahoo has nice icons in its sprite, spread out equidistant from each other.


Google sticks to its minimalist design principle with its minimalist CSS sprite.


Dragon Interactive19
A design agency with a colorful, vivid CSS sprite for the navigation menu.


A huge colorful and qute chaotic CSS sprite on a site of a Portugiese TV-channel (thank you, António Manuel Cardoso!).


CSS Sprites are used to combine many frequently used graphic elements, such as navigation elements, logos, lines, RSS icons, buttons, etc. Conversely, they are not used for any kind content that is likely to change frequently upon release.

Articles About CSS Sprites

CSS Sprites: Image Slicing’s Kiss of Death23
The legendary introductory article about CSS sprites on A List Apart.


CSS Sprites: What They Are, Why They’re Cool And How To Use Them25
An illustrated article about CSS sprites by Smashing Magazine author Chris Coyier and a blogger from Turkey, Volkan Görgülü.


How and Improve Web Performance With CSS Sprites27
Some of the busiest websites on the Web use CSS sprites to save on HTTP requests. This article shows how Yahoo! and AOL use sprites to improve performance. Note: some devices (the iPhone being the most notable) apply sprites in a memory-intensive way, which slows the device to a crawl.

What Are CSS Sprites?28
An introduction by Jason Cranford Teague.


Sprite Optimization30
Dave Shea ponders whether it actually makes sense to create large CSS sprites, combining all elements into a single image and then displaying them with the background-position property in CSS. Answer: No, do not over-complicate things. Instead, find a good compromise between quick loading time and maintainability.

CSS Sprites31

Creating Easy and Useful CSS Sprites32
A detailed introduction to CSS Sprites by Ignacio Ricci. All files can be downloaded as well.


Fast Rollovers Without Preload34
A practical example of implementing fast rollovers.


CSS Sprites + Rounded corners36
Another example from practice, this one explaining how to display rounded corners using CSS Sprites.


CSS Image Sprites38
An extensive tutorial with examples, tips, suggestions and best practices.

Optimize Your Website Using CSS Image Sprites39
This very detailed tutorial by Andrew Johnson explains what CSS sprites are, why they are important, how they work and how to implement them.


Animated GIF For CSS Sprites41
This article discusses one of the more bizarre uses of CSS sprites: as an animated GIF.


Image Sprite Navigation With CSS44
Learn how to create a simple menu with the hover effect.


Advanced CSS Menu46
Implement the hover effect with CSS sprites.


Creating and Using CSS Sprites48
A very basic tutorial about CSS sprites by David Walsh.

CSS Sprites Screenshot49

Screencasts about CSS Sprites

How to Use CSS Sprites50
David Perel explains the basics of CSS sprites and how to use them in your website design. 10 minutes.

Creating Rounded Buttons With CSS Sprites51
Continuing the above sprites tutorial, David shows how to create dynamic rounded-corner buttons with CSS.

Exactly How to Use CSS Sprites52
In this screencast, Andres Fernandez shows how to use CSS sprites to improve loading time and decrease HTTP requests.

How To Use CSS Sprites53
This screencast, Smashing Magazine author Chris Coyier shows how to use CSS sprites in practice, by taking what would have been eight different images and combining them into one. As an added bonus, he then expands on the idea with jQuery by building a little accordion widget.

Faster Page Loads With Image Concatenation54
For complex web apps, the quantity and resulting latency of icons and images used can greatly affect page load times. And developers usually try to reduce, rather than increase, page load times for their sweet Web apps.

CSS Image Sprites In 10 Minutes55
Another screencast that explains how to use CSS sprites for a navigation menu.

CSS: Using Percentages in Background-Image56
This article explains the background-position property, which is essential to implementing CSS sprites.

CSS Image Maps With CSS Sprites

With CSS Sprites, the hover effect doesn’t have to be applied to the whole element. Using a negative background-position value, you can create pure CSS-based image maps. Below, you’ll find some techniques in which CSS sprites are used for this purpose.

CSS Image Maps Using Sprites57
A basic example of a CSS-based image map with a negative background-position value. Try hovering over the image. Compare this with the classic example without CSS sprites58.


City Guide Map Using Sprites60
Another example, with horizontally positioned hover areas.


Advanced Map Using Sprites62
A more advanced technique by Frank Manno.


CSS Sprites Techniques

CSS Sprites 264
Dave Shea expands on the classic CSS sprites technique with jQuery. His technique allows for animation between link states, while still being fully degradable for visitors who do not have JavaScript enabled.

CSS Sprites2 Refactored: Building an Unobtrusive jQuery Plug-In65
Joel Sutherland describes his jQuery plug-in, which cleans up Dave Shea’s function and allows for more control over the animation with less initial configuration.

CSS Sprites Screenshot66

Background Repeat and CSS Sprites67
CSS sprites are a great way to improve the loading speed of your pages. One of the problems you might face with sprites is how to deal with cases where the background repeats. The rule is pretty simple: if you want the background to repeat vertically (top to bottom), place the images in the sprite horizontally (left to right) and make sure the individual images in the sprite have the same height. For the opposite case, when you want to repeat horizontally, sprite vertically.

CSS Sprite: Photoshop Script Combines Two Images for CSS Hover68
This article presents a simple JSX Photoshop script for creating image sprites, and you can also assign a keyboard shortcut to it.

CSS Sprites Screenshot69

Extending CSS Spriting70
Jennifer Semtner extends the classic CSS sprites technique to non-background images and discusses what to consider when using CSS Sprites for the design.

Sliding Doors Meets CSS Sprites71
Combining the ideas behind Dave Shea’s CSS sprites and Douglas Bowman’s sliding doors technique, this post assumes you have a good understanding of Bowman’s article “Sliding Doors of CSS72.”

How to Preload Images When You Can’t Use CSS Sprites73
This article addresses the problem that occurs with CSS sprites when the user resizes text. The idea is to combine the images into two images, rather than one. Then you place the image being shown on hover as the background image of another element (preferably a containing element), positioned just off screen.

JavaScript Sprite Animation Using jQuery74
Alex Walker combines visual jQuery effects with CSS sprites to achieve the “page turn” effect.

CSS Sprites Screenshot75

IE6, CSS Sprites and Alpha Transparency76
Julien Lecomte shows how to combine CSS sprites, PNG transparency and Internet Explorer 6 compatibility using the AlphaImageLoader hack.

CSS Sprite Generators

Data URI Sprites77
DURIS (Data URI [CSS] Sprites) is a new method to manage website’s background images. It’s aimed to replace classical CSS Sprites. The new technique allows you to apply any corrections to your make-up, allows you to minimize number of requests for design-related data that is used on the webpage and uses text (non graphic) format of image data presentation. It also solves all problems with scaling for background images and combines images of different types and axes of repetition.


This simple tool lets you upload multiple images and generates CSS code for the sprite.

Sprite Creator 1.080
This tool allows you to upload an image and create the CSS code for selected areas of the sprite.

CSS Sprite Generator81
A Drupal module for building CSS sprites.

CSS Sprites Generator82
This tool allows you to upload multiple files and generate a sprite out of them. It also gives you the CSS code (the background-position value) for each image in the sprite.

Projekt Fondue CSS Sprite Generator83
This generator lets you ignore duplicate images, resize source images, define horizontal and vertical offset, define background and transparency color, assign CSS class prefixes and various other things. It also supports many languages. The source code is available for downloading and is covered by a BSD license. Want to run a local copy? Well, you can do that, too.


A Java-based desktop application that parses special directives that you can insert into your original CSS to mark individual images to be turned into sprites. It then builds sprite images from the collected images and automatically inserts the required CSS properties into your style sheet, so that the sprites are used instead of the individual images.

You can work with your CSS and original images as usual and have SmartSprites automatically transform them to the sprite-powered version when necessary. A PHP version86 is available as well. Open-source. Check also Chris Brainard’s Sprite Creator 1.087.

Bonus: How Does The background-position Property Work?

The background-position property, together with CSS specificity88 and CSS floats89, is probably one of the most confusing and counter-intuitive of CSS properties.

According to CSS specifications, the background-position takes two (optional) arguments: horizontal position and vertical position. For example:

.introduction {
		background-image: url(bg.gif);
		background-position: [horizontal position] [vertical position];

Using this property, you can define the exact position of the background image for the block-level element (list item li). You can use either % or px units (or mix both) to define the starting position (i.e. the upper-left corner) of the displayed part of the master image. Alternatively, you could use the following keywords: top left, top center, top right, center left, center center, center right, bottom left, bottom center, bottom right.

Hence, in background-position: x% y%, the first value is the horizontal position, and the second value is the vertical position. The top-left corner is 0% 0%. The bottom-right corner is 100% 100%. If you specify only one value, the other value will be 50%.

For instance, if you use,

ul li {
		background-image: url(bg.gif);
		background-position: 19px 85px;

… then the background-image will be positioned 19 pixels from the left and 85 pixels from the top of the list item element.

As SitePoint’s reference article explains90: “a background-image with background-position values of 50% 50% will place the point of the image that’s located at 50% of the image’s width and 50% of the image’s height at a corresponding position within the element that contains the image. In the above case, this causes the image to be perfectly centered. This is an important point to grasp — using background-position isn’t the same as placing an element with absolute position using percentages where the top-left corner of the element is placed at the position specified.”

You can find a detailed explanation of the property in the article “background-position (CSS property)91” on SitePoint.

You may want to take a look at the following related posts:



  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96

↑ Back to top Tweet itShare on Facebook

Sven is the co-founder and former CEO of Smashing Magazine. He's now writing at his Conterest Blog, where he focuses on blogs, content strategy and publishing — all in German.

  1. 1

    what the other PORTUGUESE guy said…
    It would be nice if you corrected the error.

    .pt domains are from Portugal; .pl domais are from Poland

  2. 102

    Believe it or not. has one of best sprite implementations

  3. 203

    One of the best posts

  4. 304

    way to copy/paste my second point from comment #60 but completely ignore the first (about sprite printing issues).

    Backgrounds don’t print out, so if you have any icons that absolutely must show in print, spriting is not for you.

    Was that so hard to explain?

  5. 405

    As pointed out for many preivous comments “” is portuguese not polish. .pt is the portuguese TLD. Whenever you are able to you should correct that ;)

    Also in the same text:
    “A huge colorful and qute chaotic CSS sprite on a site of a Polish TV-channel (thank you, António Manuel Cardoso!).”
    You may mean “quite” instead of “qute”.

    Good work with this article by the way.

  6. 506

    Ok now you have corrected it to portuguise :S Please be correct.
    I will paste the text corrected so it is easier (just copy paste)
    “A huge colorful and quite chaotic CSS sprite on a site of a Portuguese TV-channel (thank you, António Manuel Cardoso!).”

    Thank you!

  7. 607

    @ Chris B
    “Internet speed are growing all of the time. It doesn’t really matter how many HTTP requests are required”

    No they are not. Yes it does.

    Latency is teh suck.

  8. 708

    Thanks, I have seen this technique used, but never investigated the in’s and out’s.

    It seems like this would take a lot of extra time to design, but that may be worth it to cut down site load time depending on site traffic. The Projekt Fondue CSS Sprite Generator etc… will probably really help with design time.

    I would think it would be a pain to update images. It is so easy to just FTP over image files if you want to replace them. I would hate to have to plug them in to a master image each time I wanted to switch out a graphic.

    Has anyone used this? Am I right, or is this less painful then it sounds?

  9. 809

    Great article…
    Further reading
    CSS sprites part1 and CSS sprites part2 (link to my last month articles)

  10. 910

    Nooooooooooooooooooooooooooooo, I was gonna submit an article on CSS Sprites!

  11. 1011

    Great technique and great post!.

    How do you track these moves on the sprite? ( I am a web strategist and as such have to deal with everything.)
    So from a server load, traffic optimization point this is awesome. User experiences – great. But I guess the analysts will start crying soon, because the reload gave them info on what just happened on that page. How to you deal with this? How do you analyse the user interactions with sprites?

  12. 1112

    Epic post!! I noticed that AddTOAny uses CSS Sprites in the widgets.

  13. 1213

    This is a good collection of references, but what about using sprites with an input type=”image” tag? I’ve got it covered if you want to link me up:

  14. 1314

    A great and comprehensive post on CSS Sprites
    I have already post about CSS sprites at my blog for css beginners with minimal code free and provided download link there. But this article is really cool for professionals

  15. 1415

    I love sprites! I just had a slicing service cut up and code a page for me and was disappointed that they didn’t use sprites for the nav.

    Great article.

  16. 1516

    darn handy, tx

  17. 1617

    William Shields

    June 26, 2009 2:47 am

    That is a truly outstanding synopsis. Good job.

  18. 1718

    A Outstanding Tutorial for Designers.
    and an impressive work with CSS.

    thank you very much

  19. 1819

    It’s good!

  20. 1920
  21. 2021

    Very nice tutorial about CSS sprites. It covers almost all the aspects of CSS sprites where they can be used, and various detailed examples. Nice job. I recently wrote a tutorial where one can use CSS Sprites to increase the interactivity of their tweet display box. Hope it would be helpful to all who learned how to use CSS Sprites from here :)
    Spice Up Your Twitter Feed Box Using CSS Sprites

  22. 2122

    Extremely thorough article on sprites. Thanks Smashing!

  23. 2223

    A very good article. I will use some of your tips on my homepage when I make another design. Thank you very much.

  24. 2324

    It seems a fully automated CSS Sprites generator isn’t covered –

  25. 2425

    i’ve seen some angry comments. since when are webdesigners an angry crowd? nice psot by the way.

  26. 2526

    Terrific post! The first time I got here and instant impressed!! Awesome! Fav+ Thanks a lot!

  27. 2627

    Great post about image sprites. Applying image sprites to your site, is one of the most important ways to optimize page speed. You can also find a tutorial about images sprites here:

  28. 2728

    like it…….
    should follow…

  29. 2829

    Nice info ,thanks…

  30. 2930

    Eduardo Storini

    July 10, 2010 3:40 am

    Now I go to work in my website with this techniquies

  31. 3031

    Great Post! Thanks!

  32. 3132
  33. 3233

    Listed this article as recommended reading in one of our recent blogs :)

  34. 3334

    Nice…Very Useful Resource For Designers…

  35. 3435

    Thanks smashing magazine. Very usefull. I have used it on my website and have boosted the speed. For abour 300kb of page size, it loads in just 3 seconds.
    Thanks once again for such useful article

  36. 3536

    Great resource the effort is appreciated

  37. 3637

    I found an awesome php library that allows you to create sprites super easy. Check out SpriteMeister (, it spits out an optimized sprite, allows for custom configurations and even updates your css offsets for you!

  38. 3738

    I doesnt affect much, keep your images quite seperate so that it doesnot display more than required or use the other after the padding and margin is applied or use the png. It works great and boosts the website opening time. I normally use this for all my big projects.

  39. 3839

    Yes Tyler K, it reduces the size and bandwidth but the main benefit of css sprites is that it reduces the server calls, which mostly takes time compared to downloading the images.

  40. 3940

    Yes Tyler K you are right, it reduces the bandwidth and the size of image. But the main benefit of it is that it reduces the time to connect and call the image from server. As in most cases the connection and calling the images takes more time than downloading the image for website. So reducing the number of image call would make the website much faster.

  41. 4041

    Great post with lot’s of information!

  42. 4142

    Everything I ever needed about Sprites is in this article!!! THANKS!

  43. 4243
  44. 4344

    All we have in the current zoo is search on key word across everything, what is really badly needed is search limited to certain applications (and their instances) and the ability to search specific categories.

  45. 4445

    a couple of broken links on this post, e.g. spritr

  46. 4546

    It is a nice tutorial.
    Another nice implementation of CSS sprite using CSS and PHP for dynamic behavior is implemented on where an image can be painted using CSS sprite. And with PHP brush (cursor) size can be controlled.

  47. 4647

    Nice job writing this up in a manner that most people can understand. I have been using sprites for rollover navigation for quite some time and I do find it’s the best way to go in terms of page load times.

  48. 4748

    What about ?
    This is online CSS sprites generator with editor and project saving, but working only in FF and Chrome
    Demo on this site:

  49. 4849

    A new tool for generating webp sprites
    unique feature such as

    * easily re-editable
    * easy to share between co-workers and demo viewers
    * can create repeatable items in same sprite
    * algoritm to pack them as tight as possible
    * can create lowDef and hiDef retina sprite (if you start with the bigger image)


↑ Back to top