CSS sprites is a technique to combine unlimited number of images into one to improve the performance of your web page.Have you ever seen the CSS technique where the “on” and “off” states of a button are contained within the same image and are activated by shifting the background-position? Think of CSS Sprites as an extension of that technique.With millions of users Google,Yahoo!,MySpace,YouTube and AOL do everything they can to improve the user experience. As all of them use CSS sprites to save numerous HTTP requests for their intricate interfaces.
What does css sprites does…
Group multiple images together (usually icons or decorative images) into one sprite
Evenly space these images, aligned into one or more lines
Set this sprite to the background image of an element (usually a list)
Position the sprite to display the appropriate image by shifting the X or Y position by a multiple of the spacing
Enjoy the increased speed and reduced HTTP requests
Create your own CSS Sprite…
Step1-Create an image (or collect it from anywhere)using photshop,fireworks,gimp etc.. depends on your choice.
#nav li a.item1 {background-image:url('../img/image1.jpg')}
#nav li a:hover.item1 {background-image:url('../img/image1_over.jpg')}
#nav li a.item2 {background-image:url('../img/image2.jpg')}
#nav li a:hover.item2 {background-image:url('../img/image2_over.jpg')}
#nav li a.item3 {background-image:url('../img/image3.jpg')}
#nav li a:hover.item3 {background-image:url('../img/image3_over.jpg')}
#nav li a.item4 {background-image:url('../img/image4.jpg')}
#nav li a:hover.item4 {background-image:url('../img/image4_over.jpg')}
#nav li a.item5 {background-image:url('../img/image5.jpg')}
#nav li a:hover.item5 {background-image:url('../img/image5_over.jpg')}
As above image displays that img1,img1_over,img2,img2_over
it means that when background position changes image display changes
By using CSS Sprites we are able to lighten up this interface.We may use one single image instead of 6 images.We can combine them into one big image.Create a new image that is as wide as your widest image and and as tall as the combined height of all your images plus X pixels, where X is the number of images you have. Now place you images into this new image, left aligned, one on top of the other with one pixel of white space in between.![]()
Now look at css after combining the images into one
#nav li a.item1 {background-position:0px 0px;}
#nav li a:hover.item1 {background-position:0px -72px;}
#nav li a.item2 {background-position:0px -143px;}
#nav li a:hover.item2 {background-position:0px -215px;}
#nav li a.item3 {background-position:0px -287px;}
#nav li a:hover.item3 {background-position:0px -359px;}
#nav li a.item4 {background-position:0px -431px;}
#nav li a:hover.item4 {background-position:0px -503px;}
#nav li a.item5 {background-position:0px -575px;}
#nav li a:hover.item5 {background-position:0px -647px;}
There is a single background-image applied to the anchor element itself, and the unique classes merely shift the background position with negative Y coordinates.
During this the HTTP Request time reduces and size of images reduces.This is done for only 6 images ,and if you are usimg it in your website then you will be able to find some dynamic changes.
Related posts:
- How to customize the Thesis Header in few easy steps Header is quite sensitive area of any layout as it...

{ 1 trackback }
{ 9 comments… read them below or add one }
Hey Honey Very helpful post and worth sharing. Though I think I need to digg more into the detail of every step you explained. Earlier I used to think that plugin is the best way to optimize the blog, but I was wrong.. I like the idea of hosting images on sub domains..
This comment was originally posted on honeytech
Hey harshit
Good work mate…
very useful tip. I think you are using the same trick on your blog. I have to implement it. Meanwhile I’m accessing your blog via mobile Internet connection and your load time is fast
@Harsh
yeah right nw i m wrking on it and found it very useful.
I think u got it very well……
@Harsh
Thanks.
Due to page length and time scope, i escaped few things in this posts and will include in upcoming posts.
This comment was originally posted on honeytech
@Honey
Will be waiting eagerly for your upcoming post on wordpress optimization series.
This comment was originally posted on honeytech
Meanwhile could you please enable the subscribe to comment feature, I want to subscribe to all the comments on this post, but I can’t find it.
Thanks ..
This comment was originally posted on honeytech
How to decrease website loading time and improve performance…
Internet users today are quite restless and rarely wait if your website is very heavy to load in their normal internet speed. Web site optimization is an important part of your ambition that decides the productivity of the websites. So avoid frustratin…
This comment was originally posted on honeytech
Interesting ideas indeed! I was actually thinking about comments last night and this morning
This comment was originally posted on honeytech
Does shifting the CSS / Image files into a subfolder then require you to hardcode all those images to that folder? How else will the browser know where to look?
(new to this thanks)
This comment was originally posted on honeytech