The State Scope Method

Image Replacement That Works.

The images-on State Scope is currently off. Turn it on.
The images-on State Scope is currently on. Turn it off.

About State Scopes

A State Scope is a design pattern that lets a web developer switch into a specific “state”, in which certain CSS rules are applied to the page. The pattern can be used for a variety of things, but most people will use it for image replacement.

The two titles at the top of this page use State Scopes for image replacement. So go ahead—disable images, disable JavaScript, and load this page on an old web browser. These images are 24-bit PNG files with an alpha channel, and there is no semi-visible text leaking through. When you're ready to implement it on your own web site, you can learn more about image replacement with State Scopes from this SitePoint article.

One feature that comes with State Scopes is the ability to toggle them on and off quite easily. You can click the toggle link at the top of this page (which executes essentially a single line of JavaScript) to toggle image replacement on and off, and see how gracefully your page can degrade.

The Benefits of Image Replacement with State Scopes

Combining State Scopes with a clever way to check if images are enabled in the visitor's browser produces a near-perfect image replacement method—one that provides a number of advantages over the other techniques that are currently in use. For example, it...

You've got the power.

Because you have the flexibility to have entirely different CSS applied to the page when images are enabled and disabled, you can achieve some fairly creative effects with your text stand-ins. Click the toggle link at the top and take a look at what was done (fairly easily) with the logo title on this page.

Other things you can try with State Scopes:

Paste this code into your page:

You can get started with State Scopes and image replacement by pasting the code below into the <head> section of your page. It has been minified down to 672 bytes of script.

The State Scope design pattern is a concept created by Paul Young.
For a CSS development environment with built-in State Scope support, see Stylizer.