--- url: "https://www.w3.org/WAI/WCAG22/Techniques/aria/ARIA24" titulek: "ARIA24: Semantically identifying a font icon with role=\"img\" | WAI | W3C" h1: "Technique ARIA24:Semantically identifying a font icon with role=\"img\"" popis: "" jazyk: "en" kanonicka: "" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 04:42:38" znaku: 6424 slov: 969 kodovani: "utf-8" sha256: "c4e126779503de54df81b1d9368286592a26916a62a10533759f0b423246966e" --- # Technique ARIA24:Semantically identifying a font icon with `role="img"` ## About this Technique This technique relates to [1.3.1 Info and Relationships](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships) (**Sufficient**). This technique applies to content using [WAI-ARIA](https://www.w3.org/TR/wai-aria/). Techniques are examples of ways to meet Web Content Accessibility Guidelines (WCAG). They are **not required** to meet WCAG. Content can satisfy the normative requirements of WCAG even if it does not use any of the documented techniques. See [About WCAG Techniques](https://www.w3.org/WAI/WCAG22/Techniques/about). ## Description The objective of this technique is to show how to semantically identify an element that uses a font file for icons. When a user overrides font-family these icons typically disappear unless there is a means to identify them. The point is to provide a technique to differentiate icon fonts from general font (text) usage. Some low vision users need user stylesheets, scripts, or extensions to override the fonts on a page to perceive text content. However, they need to be able to perceive icon fonts that are meaningful, such as a star signifying a favorite, or an email icon in a link. The key is for the author to semantically markup icon fonts with `role="img"`. Then the user's font replacement selector can hook into that semantic and exclude `role="img"`. This results in those icon fonts being shown. ### Basic principle of the technique #### 1. Author adds a font-face to the CSS The first step is used for adding a font face with icons via the CSS file. ``` @font-face { font-family: 'IconFontRoleImg'; } .icon, [class^="icon-"], [class*=" icon-"] { font-family: 'IconFontRoleImg' !important; } .icon-star-bg:before { content: "\e982"; } ``` #### 2. Author adds the font classes to the HTML The second step adds classes, the role="img" attribute for semantics and an accessible name. ```

``` #### 3. User CSS file replaces the font-family except the icon file The third step uses the ":not selector" in combination with the "[attribute] selector" to only replace font faces for regular text. ``` *:not([role="img"]) { font-family: Verdana, sans-serif !important; } ``` ## Examples ### Example 1: Star Icon Font used as an indicator (not interactive) In this example a star icon is used to indicate a favorite. It is not interactive and does not disappear if the user overrides the font family via CSS. #### Author CSS ``` .icon { font-family: 'IconFontRoleImg' !important; } .icon-star-bg:before { content: "\e982"; } ``` #### HTML ##### **- Instead of... -** ```

``` ##### **- Do... -** ```

``` #### User CSS ``` *:not([role="img"]) { font-family: Verdana, sans-serif !important; } ``` #### Working example: [Star Icon Font used as an indicator (not interactive)](../../working-examples/aria-icon-font-img-role/#example1) ### Example 2: Two colored / stacked star Icon Font used as an indicator In this example a two colored star icon is created by stacking two fonts with different colors on top of each other. This way it's possible to mimic only half the star is filled. It is not interactive and does not disappear if the user overrides the font family via CSS. #### Author CSS ``` .icon { font-family: 'IconFontRoleImg' !important; } .icon-star-bg:before {content: "\e982"; } .icon-star-half:before {content: "\e983"; } ``` #### HTML ##### **- Instead of... -** ``` ``` ##### **- Do... -** ``` ``` #### User CSS ``` *:not([role="img"]) { font-family: Verdana, sans-serif !important; } ``` #### Working example: [Two colored / stacked star Icon Font used as an indicator](../../working-examples/aria-icon-font-img-role/#example2) ### Example 3: Email Icon Font in a link WITHOUT visible text In this example an email icon is in a link with no visible text. It does not disappear if a user overrides font family. The icon font is identified by assistive technology as a "link image" and the name "Email" (keyboard or mouse). #### Author CSS ``` .icon { font-family: 'IconFontRoleImg' !important; } .icon-email:before { content: "\e93e"; } ``` #### HTML ##### **- Instead of... -** ``` ``` ##### **- Do... -** ``` ``` #### User CSS ``` *:not([role="img"]) { font-family: Verdana, sans-serif !important; } ``` #### Working example: [Email Icon Font in a link WITHOUT visible text](../../working-examples/aria-icon-font-img-role/#example3) ### Example 4: Multiple Icon Fonts as part of another sematic element WITH visible text This example already has a visible text label in the link to be used as an accessible name, the mail and chevron font icons must stay visible when the font family is changed. This can be done by ensuring the icons are contained in their own element and the attribute `aria-hidden="true"` is used so the font icons will be ignored by assistive technologies. #### Author CSS ``` .icon { font-family: 'IconFontRoleImg' !important; } - See style declarations in HTML examples - ``` #### HTML ##### **- Instead of... -** ``` Email ``` ##### **- Do... -** ``` Email ``` #### User CSS ``` *:not([role="img"]) { font-family: Verdana, sans-serif !important; } ``` #### Working example: [Multiple Icon Fonts as part of another sematic element WITH visible text](../../working-examples/aria-icon-font-img-role/#example4) ## Tests ### Procedure For each font icon check that: 1. The element providing the font icon has `role="img"` . ### Expected Results - #1 is true. Back to Top