This example inserts an image before all links. Two content values are provided. The later content value includes an image with alternative text that a screen reader can output as speech. If a browser does not support alternative text, this declaration will be considered invalid, with the previous content value displaying. This fallback content list includes an image and the message " - alt text is not supported - ".
HTML
<a href="https://www.mozilla.org/en-US/">Mozilla Home Page</a>
CSS
The CSS to show the image and set the alternative text is shown below. This also sets the font and color for the content. This will be used on browsers that display the alternative text and in browsers that don't support alternative text and show the the fallback content value.
a::before {
content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico")
" - alt text is not supported - ";
content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico") /
" MOZILLA: ";
font:
x-small Arial,
sans-serif;
color: gray;
}
Result
If using a screen reader, it should speak the word "MOZILLA" when it reaches the image. If supported (if the "alt text is not supported" is not showing), you can select the ::before pseudo-element with your developer tools selection tool, and view the accessible name in the accessibility panel.
In browsers that don't support the alternative text syntax the whole declaration containing the alt text is invalid. In this case, the previous content value will be used, showing the image and "alt text is not supported" text.