CSS Image Replacement and CSS Sprites



Image Replacement

"Classic" Image Replacement

CSS image replacement is a technique of replacing a text element on a web page with an image. Examples include logos, links and headings on a website.

To improve your page rank with the search engines (SEO), you want to use real HTML text. But for an attractive website, you may want your links to be images, or desire a certain type font for your headings. You CERTAINLY want your actual logo displayed - NOT just text.

The original technique (FIR) for replacing text with an image is named for Todd Fahrner, one of the persons originally credited with the idea. The concept is very simple. Using your logo as an example, we write the text (“Your Company Name”) and surround it with two sets of basic HTML tags.

We then use CSS to hide the HTML text and display a background image of your company logo. The markup for the HTML is:

			<div>
			<span> My Company Name </span>
			</div>

The CSS needed to achieve the swap with the image of the actual logo consists of two simple rules. The first uses background properties to pull the image into the background of the div:

		div {
		    background-image: url("My Logo.gif");
		    background-repeat: no-repeat;
		    height: 50px;
		    }

The height property in that rule matches the actual height of the image, ensuring the div is tall enough to display all of the image. The background-repeat property ensures the image only appears once, instead of tiling across the entire width of the web page.

Now to "hide" the raw text which we wrote in the HTML. This is where <span> tag comes in, as we need a second element so we can address it separately.

Hiding the text is now simple:

		span {display: none;}

There are some drawbacks to image replacement techniques. Most methods suffer from problems for users who turn images or CSS off, as well as accessibility issues involving screen readers for the disabled that read web pages out loud.


To date, no method has emerged as the “Holy Grail” of text - image replacement. Click here for an excellent examination of current alternatives to the Fahrner method by Chris Coyier.


fancy rule divider graphic

CSS Sprites Image Replacement

Have you ever heard about the CSS technique where the “on” & “off” states of a button are contained within the same image — activated by shifting the background-position? CSS Sprites are an extension of this concept. Instead of just two or three images being combined into one, you can combine an unlimited number of images into one large image!


fancy rule divider graphic

Advantages of CSS Sprites

1) Reducing the download size of the file - though most people assume than the master image is larger than if all of the images were sliced individually, it's actually a lot smaller. CSS sprites reduce file sizes dramatically, as each individual image has minimum file sizes needed to store color tables, etc.

2) Less code - markup is nice and clean. Replacing the sprite images is very simple since here is only a single image and all of the offsets and sizes and are controlled in a single CSS file.

3) Pages load faster - every single image is a separate "HTTP request" to the browser, so fewer images result in fast page loading.

Take this web page as an example:


mini tab navigation image

There are seven tabs in the header navigation bar, as well as four navigation buttons each on the left and right of the site, for a total of fifteen navigation images.

Each navigation image also has three states: link, hover and active. Using the above Fahrner image replacement method (or "slices" from Photoshop, etc.) this would require 15 X 3 = 45 separate images to achieve!

The web page you are viewing contains a grand total of THREE images for the three navigation areas. It could have actually been achieved with just ONE!
Click here to download the header navigation image to view an example.

Using the CSS background position property, a "window" is simply shifted about the master image to the proper spot for each particular link. Kudos to Elliot Jay Stocks, where I learned how to implement the technique as used on this website. His site is currently under revision, so I can't link directly to his explanation.

A List Apart has a good article on the subject here.

– Professional Website Design & Development · Search Engine Optimization · Freelance Graphic Design Services –

Graphic Connection provides websites styled with Cascading Style Sheets (CSS) in Kansas City, Independence, Olathe, Kansas, Overland Park, Blue Springs, Missouri, Belton, Excelsior Springs, MO, Gardner, KS, and Gladstone               Graphic Connection provides websites styled with Cascading Style Sheets (CSS) in Grandview, Missouri, Lansing, Leawood, Leavenworth, Kansas, Lees Summit, Lenexa, KS, Liberty, Merriam, Ottawa, Prairie Village, Raymore, Raytown, MO, Shawnee, Avondale and Basehor, Kansas               Graphic Connection provides websites styled with Cascading Style Sheets (CSS) in Birmingham, Bonner Springs, Kansas, Buckner, Claycomo, Countryside, KS, De Soto, Edgerton, Edwardsville, Fairway, Garden City, Glenaire, Grain Valley, MO, Greenwood, Missouri, Harrisonville, Houston Lake and Kearney               Graphic Connection provides websites styled with Cascading Style Sheets (CSS) in Lake Lotawana, Lake Quivira, Lake Tapawingo, Lake Waukomis, Lake Winnebago, MO, Lawson, Levasy, Lexington, Linwood, Lone Jack, Missouri, Louisburg, Mission, Mission Hills, KS, and Mission Woods               Graphic Connection provides websites styled with Cascading Style Sheets (CSS) in Missouri City, Napoleon, North Kansas City, MO, Northmoor, Oak Grove, Missouri, Oaks, Oakview, Oakwood, Oakwood Park, Odessa, Orrick, Paola, Parkville, Peculiar, Platte City and Platte Woods               Graphic Connection provides websites styled with Cascading Style Sheets (CSS) in Pleasant Valley, Pleasant Hill, Randolph, Richmond, River Bend, Riverside, MO, Roeland Park, Kansas, Sibley, Smithville, Spring Hill, Sugar Creek, Tonganoxie, Unity Village, Weatherby Lake, Wellington, Westwood, Kansas and Westwood Hills.