Hello!
A few years ago an idea of a code style practice has been written down (but never validated and/or respected) here.
The initial idea was:
Icon fonts must have a role=“img” attribute.
For example:
xwiki.iconset.render.wiki = <span class=“fa fa-$icon” role=“img”></span>
I’m proposing thereafter a revised version of this code style practice:
Icon themes must have an <img> nature and an alternative text.
For example:
xwiki.iconset.render.wiki = <img class=“fa fa-$icon” alt="$icon"></img>
Here are the points covered by this code style rule:
- (the initial point) use semantic HTML instead of non semantic HTML. This is a good practice that’s particularly useful when asserting accessibility.
Sources:- axe-con 2022 conference
- Article written by the Chrome team
- Icon fonts should always use semantic HTML to display their images. The role=img could do the same thing as an img HTML nature, however support is wider for the HTML balise.
If you can use a native HTML element [HTML51] or attribute with the semantics and behavior you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible**, then do so**.
From aria specs
- Images should be labelled:
1.1.1 Non-text Content: All non-text content that is presented to the user has a text alternative that serves the equivalent purpose, except for the situations listed below. (Level A)
From the Web Content Accessibility Guidelines (WCAG) 2.1
What do you think about using this rule for icon themes from now on?
I’m looking forward to your feedback about a rule that would make sure icon themes are accessible.