Using Image replacement techniques

Image ReplacementThis week Ive been trying out a lot of image replacement techniques in main headings, and their are quite a few available. If you have a graphical header logo on a website, with the sites name, often you wont want to have another heading as plain text. Yet, you should want to have the heading readable by screen-readers, and you also want the SEO benefits of the heading.

Ive rounded up my favorite methods, and this entry will show you how to use them, and when to use them.


Method 1 – Stick the image in the Heading tag

This method simple involves putting your logo in a heading tag, and giving it relevant alt and title attributes. It works well with simple logos, but if you want cool rollovers etc, you will need a different method.

(X)HTML

<h1>
   <a href="home.htm" title="homepage">
      <img src="logo.gif" alt="Site name" />
   </a>
</h1>

Suits – Simple logo’s with an alt tag, and possibly a link

Pro’s – Alt text should remain visible with images off, logo visible when CSS disabled

Con’s – No css rollovers, you must resort to Javascript

Method 2 – Phark Method – modified


This method involved using a CSS background image to show the logo. If CSS is disabled you still see the heading text, however with images off and CSS on the logo is hidden, which is a shame.

It works by indenting the text out of sight, and showing the background image. I use this one when I have a transparent logo, e.g. A transparent png, since other methods (like Gilder/Levin below) show the heading text underneath the image.

My modded code below also allows pretty rollovers, a nice addition.

(X)HTML

<h1>
    <a title="Homepage" href="home.htm">
    <span>
        Site name
    </span></a>
</h1>

CSS

h1 a span
{
    	height:164px;
    	width:219px;
    	background: url('logo.png') no-repeat;
    	text-indent: -5000px;
}
h1 a:hover span, div#header h1 a:focus span
{
    	height:164px;
    	width:219px;
    	background: url('logoHover.png') no-repeat;
    	text-indent: -5000px;
}

Suits – Headings when you want a link, and your logo is transparent.

Pro’s – Text displayed when images off, transparent images work, css rollovers work.

Con’s – Breaks with images off and CSS on.

Method 3 – Gilder/Levin Method – modified

This method is my favorite when using opaque images. It works by hiding the text with a background image via CSS, it does however need some un-semantic markup; but thats a small price to pay. The span is basically positioned to cover up the header text, thats the reason it needs to be opaque. And remember; the width and height must match the image!

(X)HTML

<h1 id="header">
	Site name<span></span>
</h1>

CSS

h1#header
{
      margin:0; padding:0;
      position:relative;
      width:316px; height:29px;
      overflow:hidden;
}
h1#header span
{
      display:block;
      position:absolute;
      width:316px; height:29px;
      margin:0; padding:0;
      background:url(logo.gif) top left no-repeat;
}

Suits – Headings when you want a link, and your logo is opaque.

Pro’s – Text displayed when images off and also when CSS off.

Con’s – Cannot use a transparent image.

Conclusion

So they were my favorite methods, but are they best? DO you have better solutions? Leave a comment and tell me your views on image replacement.

Related reading

Found this post useful? Why not buy me a coffee!

Related Entries

7 Responses to “Using Image replacement techniques”

RSS feed for comments on this post.

  1. Will says:

    Good article. I use the Phark Method i think

    Comment made on February 12, 2007 at 10:00 am

  2. Anthony Brewitt says:

    I have been playing with some of these and prefer A and B myself. Everybody’s heard of the Flash image replacement but my problem with that is your users have to have the flash plug in, I think this adds another layer of complications. But the futures bright as I am sure I remember reading that css3 has font embedding. Lets just hope css3 arrives in our lifetimes.

    Comment made on February 12, 2007 at 10:01 am

  3. Alex says:

    There seems to be a bit of confusion going on ATM. Method 1 isn’t image replacement. The whole concept behind image replacement (rightly or wrongly) is to take garden-variety text and replace it with an image version of the same text. There is nothing to replace there.

    The default behaviour of any browser (AFAIK) is to display the ALT text whenever the image isn’t available, which is what is happening there.

    Putting a H1 around the image may cause the ALT text to appear larger in non-IE browsers (even IE7 still shows all ALT text 12px high with the ‘missing image’ icon — regardless of H1s, etc), but whether ‘the Google’ and other SEs would give your ALT text the importance of other H1 content is doubtful IMHO.

    That doesn’t mean it’s wrong. It’s still the safest way to operate generally, but it doesn’t really qualify as IR.

    Comment made on February 12, 2007 at 10:02 am

  4. 3:00 says:

    This is great info. Does the third option ensure that search engines will not see this as a black hat technique?

    Comment made on January 25, 2008 at 7:53 pm

  5. Joseph Zimmerman says:

    My Favorite is the Fahrner Method

    HTML:

    Hello world!

    CSS:
    h1 {
    background-image:url(“hello_world.gif”);
    background-repeat:no-repeat;
    height:35px;
    }
    h1 span {
    display:none;
    -or- (either works and doesn’t make much difference between screen readers)
    visibility:hidden;
    }

    If CSS is disabled it will show the text but if images are disabled nothing shows unless CSS is disabled too.

    Comment made on November 8, 2008 at 7:36 am

  6. Joseph Zimmerman says:

    Sorry About the Last post. Under HTML I wanted:

    Hello World

    Comment made on November 8, 2008 at 7:39 am

  7. Joseph Zimmerman says:

    Once again sorry. I’ve got it figured out now. I’m just redoing the whole post. My Favorite is the Fahrner Method:

    HTML:

    &lt;h1&gt;&lt;span&gt;Hello World&lt;/span&gt;&lt;/h1&gt;

    CSS:

    h1 {
    background-image:url(”hello_world.gif”);
    background-repeat:no-repeat;
    height:35px;
    }
    h1 span {
    display:none;
    -or- (either works and doesn’t make much difference between screen readers)
    visibility:hidden;
    }

    If CSS is disabled it will show the text but if images are disabled nothing shows unless CSS is disabled too.

    Comment made on November 8, 2008 at 7:43 am

The comments are closed.

About this site

Blue Anvil is the online web design journal & portfolio of , a web designer from Norfolk, England. Read More »
ThemeSlice
  • Featured work - More

    • Beefjack
    • Integrity
    • theotaku.com
  • Latest Tweet - More

    • @skjreilly no problem :)
  • Out of the blue - More

    • Switched: From Shared to VPS

      It’s been about two weeks now since I made the transition from a shared reseller hosting account to a VPS (Virtual Private Server) account – impressions so far, excellent performance but fiddly to configure.

      The reason I wanted to change from shared hosting was the fact the server was always being hacked (even though ALL my scripts were secure), there was frequent downtime, support blamed me for problems every time, and it was slow as hell.

      Those used to a shared hosting environment would probably not know where to start when faced with configuring a VPS. Luckily, a lot of it was pre-configured when I received my account – certainly some of the major security holes were patched. I was not satisfied with those however. As a victim of hacking in the past (previous host swears it was not there fault, something I don’t believe) I took extra care to secure it as a much I could – configuring brute force detection, the firewall, installing mod security (excellent rules for that here: http://www.atomicorp.com/wiki/index.php/Atomic_ModSecurity_Rules) and going though multiple guides (like this one: http://www.webhostingtalk.com/showthread.php?t=468168) with a fine-tooth comb.

      The result? My pages are loading at least 6 times faster, I have had no down time (or at least have not noticed any), and I feel in control and happy. No longer am I at the mercy of shared hosts :)

      If your interested, I chose ServInt as my provider as they offered a great deal, as well as being a managed service (so I’m not on my own if I screw things up). I was tempted by the bells and whistles of Media Temple, but felt the ServInt service was better value.

    • Download Monitor 3.2.2 Maintenance Release

      Download Monitor has received some more love and has been updated. Here’s the change log from the new version:

      • Small bugfix in uploader.php – cat ID
      • Changed stats graph calculation – thanks lggemini
      • Changes to headers in download.php to avoid caching
      • File Browser fixes – $root was clashing with something….
      • exclude_cat works in all sections of download_page now
      • Removed hardcoding of /uploads/
      • Added action to download.php – should be able to use it to stop a download if you want – maybe limiting downloads per day or something? Whatever you want…
      • Made it so if you post new file on ‘edit’ screen, the post date is updated.
      • Fixed the ‘blank meta’ section which blanks out custom field values when nothing is set.
      • Moved ‘allow_url_fopen’ check.
      • Someone said downloads don’t work with spaces in the name. They do! Wasting my time sonny…
      • All work and no play make jolley a dull boy
      • Had to rename capabilities so they work. Apologies if you have to set this up again! Cheers to Mark Dingemanse.
      • {category_ID} custom format tag added. Useful if you want to send someone to its category on the DL page I guess. Also added {category_other} so when no category is set “other” is shown – this is because the download page can show an ‘other’ section if you want it to.
      • You can now manually edit the post date on the edit download screen.

      If you have edited capabilities for download monitor user permissions, you’ll have to again sorry! This is because I named them too long. Also, you should check your forced downloads still work because there was a logic error meaning they may not have been forced after-all…

      Enjoy.

    • Mahousive update to Download Monitor (3.2)

      Today I completed the update for the Wordpress Download Monitor Plugin – many tweaks, fixes, and features added. There were no changes to the database structure so people upgrading should be fine. Here is the list from the change log:

      • {user} tag added for custom formats
      • ‘autop’ option fix
      • Download page buttons applied with CSS so they are easier to customise/translate.
      • Fix for pagination bug after editing a download
      • Category output fix on edit downloads screen
      • Category urls on download page use ID rather than name to prevent errors when cats have the same names.
      • exclude_cat added to download_page shortcode
      • Localised ‘hits’ ‘date’ ‘title’ on download page
      • Option to disable the download logging
      • Read file ‘chunked’ some people found large files were corrupted so this should help (fingers crossed)
      • Added show_tags option to download page – displays x amount of tags on the download page.
      • File Browser root setting and download.php logic/mime types modified thanks to Jim Isaacs (jidd.jimisaacs.com)
      • Interface Improvements
      • Bulk edit categories, custom fields, tags, member only downloads
      • Added roles for download monitor admin – should be able to use with a role manager plugin if you want anyone other than admin to access the admin section e.g. http://wordpress.org/extend/plugins/capsman/
      • Change redirect after add
      • Edit Cat names/parents
      • Dedicated tags and thumbnails fields (they still use meta table though)

      And yes, those category link bugs are fixed at long last, and you can edit category names finally. Phew!

    • Wordpress Spam Stopper Plugin Updated

      Spam stopper has been updated to v3.1 – and most of it has been recoded. Here’s the full list of changes:

      • Added changelog to readme.
      • Email validation bug squashed
      • Cached comments now work; if user forgets to fill in antispam or makes a mistake (and the JS does not catch it) the users comment will not be lost.
      • Redone entire code to make it more efficient
      • Admin section added for changing the antispam question
      • Form ID and honeypot trap added to form
      • Fully localized

      You can get the plugin from wordpress.org: http://wordpress.org/extend/plugins/spam-stopper/

      For support, please keep my comments clean and post on either the wordpress forums or my forum.

      To help support spam-stopper you can make a donation (buy me a coffee, or several) or rate it on wordpress.org. Thanks!