Why Use CSS Sprites Part 1


September 10, 2009 By

Jonathan Crowe

You’ve heard the term bouncing around the Internet, but still not sure what, why, or how to use CSS Sprites.  I’m here to enlighten you on this neat little feature that is sure to help speed up your site.  This is part 1 of a 2 part series blog.  Part 2 will entail “How To Use CSS Sprites”.

Why would I want to use a CSS sprite?


CSS sprites reduce the total number of http requests, can reduce the total size of the images, and increase your pages load time. 

For example, if you build an unordered list and intend of having four (4) different list item images; that is 8 different HTTP requests, assuming you use a hover and are not using the CSS Sprite technique. 

Here is an example of what the CSS might look like without the CSS Sprite technique:

 

 
#nav li a {background:none no-repeat left center}
#nav li a.item1 {background-image:url('../images/image1.gif')}
#nav li a:hover.item1 {background-image:url('../images/image1_over.gif')}
#nav li a.item2 {background-image:url('../images/image2.gif')}
#nav li a:hover.item2 {background-image:url('../images/image2_over.gif')}
...

 
 

Using the CSS Sprites requires we consolidate all four of our images into one image.  I will show you more details on how this is done in part 2.  After you have the CSS Sprite image created, you will need to create the new CSS for it.  My CSS looked like this:


#nav li a {background-image:url('../images/image_nav.gif')}
#nav li a.item1 {background-position:0px 0px}
#nav li a:hover.item1 {background-position:0px -54px}
#nav li a.item2 {background-position:0px -108px;}
#nav li a:hover.item2 {background-position:0px -162px;}
...
 
 

Now, using the CSS Sprites, we were able to cut down the HTTP requests to 1 and the total file size of all the images to 26 KB.  Imagine multiplying that by all the list items you have.  It adds up very quickly. 

In the end, this will reduce on your load time and increase the user experience.  Don’t forget, in Part 2, I will show you how to make and use CSS Sprites.

 

Did you like this post?

Sign up for our Tips and Trends list and we'll let you know each week when we have a new one.

12 Ways to Get Your Business Growing Again

Categories

Web Design (15)
Web Development (21)
Misc. Website (18)
Search Engine Optimization (74)
Social Media Marketing (77)
Local Search Marketing (14)
Content Marketing (15)
PPC Advertising (11)
Digital Marketing (77)
Marketing Automation (10)
Sales Automation (8)
Company News (10)
Other (11)

Archives

Feeds




Get in touch
with us
Submit
... or call us at 407.682.2222
Sales & Marketing Technologies
© Copyright 2018 Sales & Marketing Technologies, Ltd. All rights reserved.