Avoid using background images that are anything but decoration. So avoid text in background images or other meaning in the images.
Image Sprites
Notes on accessible CSS image sprites:
- Include alternative text inside the element that the CSS background image is attached to.
- If images are enabled and Windows high contrast mode is not enabled use Javascript to add a style sheet that visually hides the text alternative, but is still available to assistive technology.
- Use JavaScript to detect when images are disabled and remove the CSS visually hidden display state of the text alternative.
- Use JavaScript to detect when Windows high contrast mode is enabled and remove the CSS visually hidden display state of the text alternative.
Windows High Contrast Mode
Fun fact, there is a Windows High Contrast Mode media query
@media screen and (-ms-high-contrast: active) {/* All high contrast styling rules */}
@media screen and (-ms-high-contrast: black-on-white) {
div { background-image: url('image-bw.png'); }
}
@media screen and (-ms-high-contrast: white-on-black) {
div { background-image: url('image-wb.png'); }
}
Off-Screen Technique
Use this when you need to include information that you want to be announced to screen reader users. Put the content you want into the container with the background image and then apply this class:
.visually-hidden {
position: absolute !important;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
padding:0 !important;
border:0 !important;
height: 1px !important;
width: 1px !important;
overflow: hidden;
}
This does not help users on IE (or older versions of Edge) who are using Windows High Contrast Mode and no screen reader, so I refer you back to the previous section.
Emoji
Yep. Emoji. Consider this technique for non-text content that is inline with text content (like emoji or icon fonts).