CSS image replacement: Difference between revisions

From HandWiki
Scavis2 (talk | contribs)
linkage
 
link
 
Line 1: Line 1:
{{Short description|Web design technique}}
{{Short description|Web design technique}}
{{CSS}}
{{CSS}}
'''CSS image replacement''' is a Web design technique that uses [[Cascading Style Sheets]] to replace text on a Web page with an image containing that text. It is intended to keep the page accessible to users of [[Engineering:Screen reader|screen reader]]s, text-only [[Software:Web browser|web browser]]s, or other browsers where support for images or style sheets is either disabled or nonexistent, while allowing the image to differ between styles. Also named '''Fahrner image replacement''' for Todd Fahrner, one of the persons originally credited with the idea of image replacement in 2003.<ref name="stopdesign">
'''CSS image replacement''' is a dated [[Web design|web design]] technique that uses [[Cascading Style Sheets]] – as opposed to other technologies, like [[Software:Adobe Flash|Flash]] – to replace text on a web page with an image containing that text. It is intended to keep pages accessible to users of [[Engineering:Screen reader|screen reader]]s, text-only [[Software:Web browser|web browser]]s, or other browsers where support for images or style sheets was either disabled or nonexistent, while allowing the image to differ between styles. One of many techniques was the '''Fahrner image replacement''', named after Todd Fahrner, who was credited with the idea of image replacement in 2003.<ref name="stopdesign">
{{cite web
{{cite web
| url        = http://stopdesign.com/archive/2003/03/07/replace-text.html
| url        = http://stopdesign.com/archive/2003/03/07/replace-text.html
Line 16: Line 16:
== Motivation ==
== Motivation ==


The typical method of inserting an image in an HTML document is via the <code>&lt;img&gt;</code> tag. This method has its drawbacks with regards to accessibility and flexibility, however:
The typical method of inserting an image in an HTML document is via the <code>&lt;img&gt;</code> element. This method has its drawbacks with regards to accessibility and flexibility, however:


* While the [[Alt attribute|<code>alt</code>]] attribute is designed for providing a textual representation of the image content, this precludes the use of HTML markup in the textual representation and causes problems{{such as?|date=January 2015}} with some search robots.
* While the [[Alt attribute|<code>alt</code>]] attribute is designed for providing a textual representation of the image content, this precludes the use of HTML markup in the textual representation.
* Using the <code>&lt;img&gt;</code> tag to show text is presentational; many Web designers argue that presentational elements should be separated from HTML content by placing the former in a CSS style sheet.
* Using the <code>&lt;img&gt;</code> element to show text is presentational. Many web designers argue that presentational elements should be separated from HTML content by placing the former in a CSS style sheet.
* Images referenced using an <code>&lt;img&gt;</code> tag cannot be easily changed via CSS, causing problems with alternative stylesheets.
* Images referenced using an <code>&lt;img&gt;</code> element cannot be easily changed via CSS, causing problems with alternative presentations.


Fahrner image replacement was devised to rectify these issues.
Image replacement techniques like Fahrner image replacement were devised to rectify these issues.


== Implementations ==
== Implementations ==
Line 105: Line 105:
* [http://www.mezzoblue.com/tests/revised-image-replacement/ Revised Image Replacement]&nbsp;– an overview of the various FIR techniques by Dave Shea
* [http://www.mezzoblue.com/tests/revised-image-replacement/ Revised Image Replacement]&nbsp;– an overview of the various FIR techniques by Dave Shea
* [https://schoberg.net/ultimate-image-replacement/ Ultimate Image Replacement]&nbsp;– a comprehensive image replacement technique by Jesse Schoberg
* [https://schoberg.net/ultimate-image-replacement/ Ultimate Image Replacement]&nbsp;– a comprehensive image replacement technique by Jesse Schoberg
* [https://css-tricks.com/css-image-replacement/ Nine Techniques for CSS Image Replacement]&nbsp;– a 2008 overview of techniques by web design magazine CSS-Tricks


[[Category:Web design]]
[[Category:Web design]]

Latest revision as of 23:03, 4 April 2026

Short description: Web design technique

CSS image replacement is a dated web design technique that uses Cascading Style Sheets – as opposed to other technologies, like Flash – to replace text on a web page with an image containing that text. It is intended to keep pages accessible to users of screen readers, text-only web browsers, or other browsers where support for images or style sheets was either disabled or nonexistent, while allowing the image to differ between styles. One of many techniques was the Fahrner image replacement, named after Todd Fahrner, who was credited with the idea of image replacement in 2003.[1]

With the introduction of CSS web font support in all major web browsers, CSS image replacement is now little used.

Motivation

The typical method of inserting an image in an HTML document is via the <img> element. This method has its drawbacks with regards to accessibility and flexibility, however:

  • While the alt attribute is designed for providing a textual representation of the image content, this precludes the use of HTML markup in the textual representation.
  • Using the <img> element to show text is presentational. Many web designers argue that presentational elements should be separated from HTML content by placing the former in a CSS style sheet.
  • Images referenced using an <img> element cannot be easily changed via CSS, causing problems with alternative presentations.

Image replacement techniques like Fahrner image replacement were devised to rectify these issues.

Implementations

The original Image Replacement implementation[1] described by Douglas Bowman used a heading, inside of which was a <span> element containing the text of the heading:

<h3 id="firHeader"><span>Sample Headline</span></h3>

Through style sheets, the heading was then given a background containing the desired image, and the <span> hidden by setting its display CSS property to none:

#firHeader
{
  width: 300px;
  height: 50px;
  background: #fff url(firHeader.gif) top left no-repeat;
}

#firHeader span
{
  display: none;
}

It was soon discovered, however, that this method caused some screen readers to skip over the heading entirely, as they would not read any text that had a display property of none. The later Phark method, developed by Mike Rundle in 2003, instead used the text-indent property to push the text out of the image's area, addressing this issue:

#firHeader
{
  width: 300px;
  height: 50px;
  text-indent: -5000px; /* ← Phark */
}

The Phark method had its own problems, however; in visual browsers where CSS was on but images off, nothing would display.

Also in 2003, Dave Shea's eponymous Shea method solves both of the issues earlier mentioned, at the cost of an extra <span>:

<h3 id="header"><span></span>Revised Image Replacement</h3>

By absolutely positioning an empty <span> over the text element, the text is effectively hidden. If the image fails to load, the text behind it is still displayed. For this reason, images with transparency cannot be used with the Shea method.

#header
{
  width: 329px;
  height: 25px;
  position: relative;
}

#header span
{
  background: url(firHeader.gif) no-repeat;
  position: absolute;
  width: 100%;
  height: 100%;
}

Over a dozen different methods has since been developed with varying degree of compatibility and complexity.[2]

References