THE MYSTERY OF CSS SPRITES: TECHNIQUES, TOOLS AND TUTORIALS
CSS Sprites have been not new. In fact, they have been a rsther than timeless technique and have managed to turn common have make have make have make have make have make make make use of of of of of of of of of of of of in Web development. Of course, CSS sprites have been not regularly necessary, but in a small incident they can move poignant advantages and improvements — utterly if you wish to revoke your server load. And if you haven’t listened of CSS sprites before, right away is substantially a great time to clarity what they are, how they work and what collection can assistance you emanate and have make have make have make have make have make make make use of of of of of of of of of of of of the barbarous technique in your projects.
What Are CSS Sprites?
The tenure “sprite” (similar to “spirit,” “goblin,” or “elf”) has the origins in mechanism graphics, in which it described a striking intent blended with a 2-D or 3-D stage by graphics hardware. Because the complexity of video games has ceaselessly increased, there was a need for intelligent techniques which could bargain with minute striking objects whilst gripping game-play flowing. One of the techniques grown saw sprites being plugged in to a master grid (see the picture below), afterwards after pulled out as indispensable by formula which mapped the on all sides of each particular striking and selectively embellished it on the screen.
Sprites were displayed over a immobile or energetic credentials image, and the positioning of the goddess was tranquil simply by the hardware controllers. The tenure was coined since the sprites seemed to “haunt” the arrangement and didn’t unequivocally exist in the striking memory.

The strange Pokemon Sprite Sheet, consisting of over 1000 striking objects. Found here. You can click on the picture for the incomparable version.
Time passed, and at the commencement of the 2000s, when on-going Web designers proposed to find alternatives to JavaScript-based rollover menus (with onMouseOver and onMouseOut effects), sprites saw a rebirth in Web development. With CSS, the elementary doing of sprites was possible, and it was many simpler and clearer than the JavaScript-based predecessor.
In 2004, Dave Shea suggested a elementary CSS-based proceed to CSS sprites formed on the have make have make have make have make have make make make use of of of of of of of of of of of of determined by those mythological video games. In this case, mixed images used via a website would be total in to the supposed “master image.” To arrangement a singular picture from the master image, one would have make have make have make have make have make make make use of of of of of of of of of of of of the background-position skill in CSS, defining the expect on all sides of the picture to be displayed. Any hover, active or concentration goods would be implemented regulating the elementary clarification of the background-position skill for the displayed element.
When the page is loaded, it would not bucket singular images one by one (nor hover-state images per request), but would rsther than load the total master picture at once. It competence not receptive to advice similar to a poignant improvement, but it essentially was: the main waste of the onMouse goods is which JavaScript-based float goods need dual HTTP requests for each image, which takes time and creates which upsetting “flickering” of images. Because the master picture is installed with the total page customarily once with CSS sprites, no one some-more HTTP requests have been indispensable for hover, active or concentration goods (because the picture is already loaded), and no “flickering” outcome occurs.
Consequence: CSS sprites revoke HTTP requests and the loading time of pages. This is the main reason because CSS sprites have been mostly used on websites with complicated traffic, where millions of page impressions would need “only” a small fragment of what could differently be 30,000,000. Hence, CSS sprites have been ordinarily used, utterly for navigation (such as for float effects), icons and buttons.
Where Are CSS Sprites Used?
CSS sprites can be used in assorted settings. Large websites can brew mixed singular images in a suggestive manner, formulating obviously distant “chunks” of the master images — the role being to keep the design maintainable and easy to update. However, a small designers go to larger lengths in their have make have make have make have make have make make make use of of of of of of of of of of of of of sprites. Essentially, the have up which sprites take depends on the trade-off in in in between maintainability and marked down server load; thus, it varies depending on the plan you have been operative on.
Here have been a small moving (and not so inspiring) examples:
Xing
Xing uses assorted icons and buttons, as well as the logo, in the sprite.

Amazon
Large, glossy and compress CSS sprites on Amazon.
Apple
Apple uses CSS sprites for assorted states of the main navigation menu.
YouTube
YouTube takes a straight proceed to the buttons and icons. The total goddess is 2800 pixels in height!
CNN
CNN uses a medium CSS goddess with the amicable icons.
Digg
Digg has utterly an enigmatic sprite, with small arrows and brackets.
Yahoo
Yahoo has great icons in the sprite, widespread out inner from each other.
Google
Google sticks to the minimalist design component with the minimalist CSS sprite.
Dragon Interactive
A design group with a colorful, clear CSS goddess for the navigation menu.
CSS Sprites have been used to brew many often used striking elements, such as navigation elements, logos, lines, RSS icons, buttons, etc. Conversely, they have been not used for any kind calm which is expected to shift often on release.
Articles About CSS Sprites
CSS Sprites: Image Slicing’s Kiss of Death
The mythological rudimentary essay about CSS sprites on A List Apart.
CSS Sprites: What They Are, Why They’re Cool And How To Use Them
An with pictures essay about CSS sprites by Smashing Magazine writer Chris Coyier.
How Yahoo.com and AOL.com Improve Web Performance With CSS Sprites
Some of the busiest websites on the Web have make have make have make have make have make make make use of of of of of of of of of of of of CSS sprites to save on HTTP requests. This essay shows how Yahoo! and AOL have make have make have make have make have make make make use of of of of of of of of of of of of sprites to urge performance. Note: a small inclination (the iPhone being the many notable) request sprites in a memory-intensive way, which slows the device to a crawl.
What Are CSS Sprites?
An key by Jason Cranford Teague.
Sprite Optimization
Dave Shea ponders possibly it essentially creates clarity to emanate large CSS sprites, mixing all elements in to a singular picture and afterwards displaying them with the background-position skill in CSS. Answer: No, do not over-complicate things. Instead, find a great concede in in in between discerning loading time and maintainability.
Creating Easy and Useful CSS Sprites
A minute key to CSS Sprites by Ignacio Ricci. All files can be downloaded as well.
Fast Rollovers Without Preload
A unsentimental e.g. of implementing fast rollovers.
CSS Sprites + Rounded corners
Another e.g. from practice, this one explaining how to arrangement dull corners regulating CSS Sprites.
CSS Image Sprites
An endless educational with examples, tips, suggestions and many appropriate practices.
Optimize Your Website Using CSS Image Sprites
This really minute educational by Andrew Johnson explains what CSS sprites are, because they have been important, how they work and how to exercise them.
Animated GIF For CSS Sprites
This essay discusses one of the some-more weird uses of CSS sprites: as an charcterised GIF.
Image Sprite Navigation With CSS
Learn how to emanate a elementary menu with the float effect.
Advanced CSS Menu
Implement the float outcome with CSS sprites.
Creating and Using CSS Sprites
A really elementary educational about CSS sprites by David Walsh.
Screencasts about CSS Sprites
How to Use CSS Sprites
David Perel explains the basis of CSS sprites and how to have make have make have make have make have make make make use of of of of of of of of of of of of them in your website design. 10 minutes.
Creating Rounded Buttons With CSS Sprites
Continuing the on tip of sprites tutorial, David shows how to emanate energetic rounded-corner buttons with CSS.
Exactly How to Use CSS Sprites
In this screencast, Andres Fernandez shows how to have make have make have make have make have make make make use of of of of of of of of of of of of CSS sprites to urge loading time and diminution HTTP requests.
How To Use CSS Sprites
This screencast, Smashing Magazine writer Chris Coyier shows how to have make have make have make have make have make make make use of of of of of of of of of of of of CSS sprites in practice, by receiving what would have been eight conflicting images and mixing them in to one. As an combined bonus, he afterwards expands on the thought with jQuery by office office building a small accordion widget.
Faster Page Loads With Image Concatenation
For formidable web apps, the apportion and ensuing latency of icons and images used can severely start page bucket times. And developers customarily try to reduce, rsther than than increase, page bucket times for their honeyed Web apps.
CSS Image Sprites In 10 Minutes
Another screencast which explains how to have make have make have make have make have make make make use of of of of of of of of of of of of CSS sprites for a navigation menu.
CSS: Using Percentages in Background-Image
This essay explains the background-position property, which is required to implementing CSS sprites.
CSS Image Maps With CSS Sprites
With CSS Sprites, the float outcome doesn’t have to be practical to the total element. Using a disastrous background-position value, you can emanate pristine CSS-based picture maps. Below, you’ll find a small techniques in which CSS sprites have been used for this purpose.
CSS Image Maps Using Sprites
A elementary e.g. of a CSS-based picture map with a disastrous background-position value. Try hovering over the image. Compare this with the classic e.g. but CSS sprites.
City Guide Map Using Sprites
Another example, with horizontally positioned float areas.
Advanced Map Using Sprites
A some-more modernized technique by Frank Manno.
CSS Sprites Techniques
CSS Sprites 2
Dave Shea expands on the exemplary CSS sprites technique with jQuery. His technique allows for existence in in in between couple states, whilst still being entirely degradable for visitors who do not have JavaScript enabled.
CSS Sprites2 Refactored: Building an Unobtrusive jQuery Plug-In
Joel Sutherland describes his jQuery plug-in, which cleans up Dave Shea’s duty and allows for some-more carry out over the existence with reduction primary configuration.
Background Repeat and CSS Sprites
CSS sprites have been a great approach to urge the loading speed of your pages. One of the problems you competence face with sprites is how to bargain with cases where the credentials repeats. The order is flattering simple: if you wish the credentials to repeat plumb (top to bottom), place the images in the goddess horizontally (left to right) and have certain the particular images in the goddess have the same height. For the conflicting case, when you wish to repeat horizontally, goddess vertically.
CSS Sprite: Photoshop Script Combines Two Images for CSS Hover
This essay presents a elementary JSX Photoshop book for formulating picture sprites, and you can additionally allot a set of keys by-pass to it.
Extending CSS Spriting
Jennifer Semtner extends the exemplary CSS sprites technique to non-background images and discusses what to cruise when regulating CSS Sprites for the design.
Sliding Doors Meets CSS Sprites
Combining the ideas at the back of Dave Shea’s CSS sprites and Douglas Bowman’s shifting doors technique, this post assumes you have a great bargain of Bowman’s essay “Sliding Doors of CSS.”
How to Preload Images When You Can’t Use CSS Sprites
This essay addresses the complaint which occurs with CSS sprites when the user resizes text. The thought is to brew the images in to dual images, rsther than than one. Then you place the picture being shown on float as the credentials picture of an additional component (preferably a containing element), positioned usually off screen.
JavaScript Sprite Animation Using jQuery
Alex Walker combines visible jQuery goods with CSS sprites to learn the “page turn” effect.
IE6, CSS Sprites and Alpha Transparency
Julien Lecomte shows how to brew CSS sprites, PNG clarity and Internet Explorer 6 harmony regulating the AlphaImageLoader hack.
CSS Sprite Generators
Data URI Sprites
DURIS (Data URI [CSS] Sprites) is a brand brand brand new process to conduct website’s credentials images. It’s directed to reinstate exemplary CSS Sprites. The brand brand brand new technique allows you to request any corrections to your make-up, allows you to minimize series of requests for design-related interpretation which is used on the webpage and uses content (non graphic) format of picture interpretation presentation. It additionally solves all problems with scaling for credentials images and combines images of conflicting sorts and axes of repetition.
Spritr
This elementary apparatus lets you upload mixed images and generates CSS formula for the sprite.
Sprite Creator 1.0
This apparatus allows you to upload an picture and emanate the CSS formula for comparison areas of the sprite.
CSS Sprite Generator
A Drupal procedure for office office building CSS sprites.
CSS Sprites Generator
This apparatus allows you to upload mixed files and beget a goddess out of them. It additionally gives you the CSS formula (the background-position value) for each picture in the sprite.
Projekt Fondue CSS Sprite Generator
This generator of electric power lets you omit transcribe images, resize source images, conclude plane and straight offset, conclude credentials and clarity color, allot CSS category prefixes and assorted alternative things. It additionally supports many languages. The source formula is accessible for downloading and is lonesome by a BSD license. Want to run a internal copy? Well, you can do that, too.
SmartSprites
A Java-based desktop focus which parses special directives which you can insert in to your strange CSS to symbol particular images to be incited in to sprites. It afterwards builds goddess images from the picked up images and automatically inserts the compulsory CSS properties in to your character sheet, so which the sprites have been used instead of the particular images.
You can work with your CSS and strange images as common and have SmartSprites automatically renovate them to the sprite-powered chronicle when necessary. A PHP version is accessible as well. Open-source. Check additionally Chris Brainard’s Sprite Creator 1.0.
Bonus: How Does The background-position Property Work?
The background-position property, together with CSS specificity and CSS floats, is substantially one of the many treacherous and counter-intuitive of CSS properties.
According to CSS specifications, the background-position takes dual (optional) arguments: horizontal on all sides and vertical position. For example:
.introduction {
background-image: url(bg.gif);
background-position: [horizontal position] [vertical position];
}
Using this property, you can conclude the expect on all sides of the credentials picture for the block-level component (list object li). You can have make have make have make have make have make make make use of of of of of of of of of of of of possibly % or px units (or brew both) to conclude the starting on all sides (i.e. the upper-left corner) of the displayed partial of the master image. Alternatively, you could have make have make have make have make have make make make use of of of of of of of of of of of of the following keywords: tip left, tip center, tip right, core left, core center, core right, bottom left, bottom center, bottom right.
Hence, in background-position: x% y%, the initial worth is the plane position, and the second worth is the straight position. The top-left dilemma is 0% 0%. The bottom-right dilemma is 100% 100%. If you mention customarily one value, the alternative worth will be 50%.
For instance, if you use,
ul li {
background-image: url(bg.gif);
background-position: 19px 85px;
},
… afterwards the background-image will be positioned nineteen pixels from the left and 85 pixels from the tip of the list object element.
As SitePoint’s anxiety essay explains: “a background-image with background-position values of 50% 50% will place the point of the picture that’s located at 50% of the image’s breadth and 50% of the image’s tallness at a analogous on all sides inside of the component which contains the image. In the on tip of case, this causes the picture to be ideally centered. This is an critical point to learn — regulating background-position isn’t the same as fixation an component with comprehensive on all sides regulating percentages where the top-left dilemma of the component is placed at the on all sides specified.”
You can find a minute reason of the skill in the essay “background-position (CSS property)” on SitePoint.
Related posts
You competence wish to take a demeanour at the following associated posts:
- 53 CSS-Techniques You Couldn’t Live Without
- Powerful CSS-Techniques For Effective Coding
- 50 Extremely Useful and Powerful CSS Tools
- CSS Float Theory
- CSS Specificity
(al)
© Smashing Editorial for Smashing Magazine, 2009. |
Permalink |
29 comments |
Add to del.icio.us | Digg this | Stumble on StumbleUpon! | Tweet it! | Submit to Reddit | Forum Smashing Magazine
Post tags: CSS, sprites, techniques, Tutorials

Originally posted here:
The Mystery Of CSS Sprites: Techniques, Tools And Tutorials
Popularity: 13% [?]
























