1

I'm trying to get a site I'm working on to be WCAG 2 compliant. The site uses image sprites and it would be a challenge to replace the usage of image sprites throughout. As such I'm trying to determine whether the following technique:

<div style="background: url(flower.png); height: 20px; width:20px;">  
  <div style="text-indent: 100%; white-space: wrap; overflow: hidden">
    A red rose
  </div>
</div>

Is sufficiently compliant. From reading the documentation... it's unclear.

For a non-decorative img tag use of alt is definitely a requirement: H37: Using alt attributes on img elements

And for a media objects, wrapping content is sufficient: H53: Body of Object

But whether using the body of a a div that has a non-decorative image background passes muster isn't very clear.

Can anyone speak to this or point me to the relevant page in the standard?

vpiTriumph
  • 3,116
  • 2
  • 27
  • 39

1 Answers1

5

There are a couple of scenarios this could be, the advice will change depending on whether it is:

  1. Content images (e.g. a gallery)
  2. Functional elements like a navigation or toolbar options.

If they are content images (which 'red rose' implies), then I think this technique applies: http://www.w3.org/WAI/GL/WCAG20/WD-WCAG20-TECHS/C30.html

In which case your approach would meet WCAG if people could display it without the image in order to read the alt-text. That might sound odd, but assistive technologies have long known how to read alt attributes, but image-replacement can be done in many ways and they may not be able to tell when it is used.

Screen reader users would probably find it ok, but other groups who need alt-text probably wouldn't be able to read the text in a 20x20px box. For example, if you turn on high-contrast mode in Windows, background CSS images are dropped and the text would not be visible.

If they are functional elements and the image is an icon, e.g. a "save" button, then you want a visible (e.g. tooltip) and programatic label, in which case I would suggest:

<div style="background: url(flower.png); height: 20px; width:20px;" 
role="button" aria-label="Save" title="Save" tabindex="0"></div>

However, you would be better off using foreground images or font-icons, as these are far more robust in different situations. For example, if you included a font-icon you could use:

 <button>
  
      <span class=”icon-save” aria-hidden="true"></span>
  
      <span class=”alt”>Save</span>
    
 </button>

With something like this as the CSS, assuming you have already imported the correct font to use:

    .icon-save:before {

       font-family: icons;
      
       content: &#x21dd; /* whatever your icon reference is */
    
    }

 .alt {
  position: absolute;
 left: -9999px;}
AlastairC
  • 3,277
  • 21
  • 15
  • 2
    Be careful about putting essential text in a title attribute, they are not reliably announced by screenreaders. – steveax Dec 11 '13 at 04:33
  • Actually I think would be pretty reliable in this (narrow) scenario, as screen readers will look for the best label for the link. I just tested it in recent versions of VoiceOver/NVDA/Jaws. Admittedly it isn't a great approach overall, but we need more info to improve on it. – AlastairC Dec 11 '13 at 17:11
  • It's user configurable and many AT users have turned that off due to noise (_viz_ the SEO folks stuffing title attributes full of things in hopes of higher page rank) – steveax Dec 12 '13 at 00:35
  • I think even if the user has turned it off, given the rules for what to use (http://www.w3.org/TR/wai-aria/roles#textalternativecomputation) it will still be read out as it is the only information. Having just come across that myself whilst checking this, I'll update my answer to suggest aria-label instead. – AlastairC Dec 14 '13 at 14:55