Icon
An icon is a compact visual element that represents actions, objects, or concepts using simplified graphical symbols. The Icon component provides a headless wrapper around icon content with proper accessibility semantics, supporting both meaningful icons (with accessible labels) and decorative icons (hidden from assistive technology).
This component is useful in buttons, menus, toolbars, and navigation where visual cues help users quickly identify functions. The consumer provides the actual icon content (text characters, SVG, or any markup), while the component handles the semantic role and ARIA attributes.
Implementation Notes
- Renders a
<span>element as the icon wrapper - Uses
role="img"for meaningful icons that convey information - Uses
aria-hidden="true"for decorative icons that should be ignored by screen readers - When
decorativeis true, theroleattribute is omitted entirely - Supports rest props spread for consumer customization
- Consumer provides icon content via the
childrenslot
Props
label: string (optional) -- accessible name announced by screen readers for meaningful iconsdecorative: boolean (default: false) -- when true, hides the icon from assistive technology and removes the img rolechildren: slot (required) -- the icon content (text, SVG, or other markup)...restProps: unknown -- additional attributes spread onto the<span>element
Usage
<!-- Meaningful icon with accessible label -->
<Icon label="Close">x</Icon>
<!-- Decorative icon hidden from screen readers -->
<Icon decorative>*</Icon>
<!-- Icon with custom attributes -->
<Icon label="Search" data-testid="search-icon">Q</Icon>
Keyboard Interactions
None -- this component is a passive container. Keyboard behavior depends on the parent interactive element (such as a button wrapping the icon).
ARIA
role="img"-- applied to meaningful icons so assistive technology treats the span as an imagearia-label="..."-- provides the accessible name for meaningful iconsaria-hidden="true"-- applied whendecorativeis true, hiding the icon from the accessibility tree
When to Use
- Use to display a visual symbol representing an action, object, or concept in buttons, menus, toolbars, or navigation.
- Use with
decorativefor icons that are purely visual and have adjacent text labels. - Avoid using a meaningful icon without a
labelprop; screen reader users would miss the icon's purpose.
When Not to Use
- Do not use as the only target of a click — wrap interactive icons in
IconButtonor another button so they pick up button semantics and focus styles. - Do not use to render a single emoji character that already has a textual meaning — use
Emojifor that. - Do not use as a substitute for a labeled image with caption — use
Figurefor content imagery. - Do not use without
labelfor an icon that conveys meaning standalone, and do not pass alabelto a decorative icon.
Headless
This headless component provides a <span> with role="img" and aria-label for meaningful icons, or aria-hidden="true" for decorative icons. The consumer provides all visual content (SVG, text characters, icon fonts) and styling.
Styles
The consumer provides all CSS styling. The component renders with a .icon class for targeting. No default styles are included — this is a fully headless component.
Testing
- Verify the component renders a
<span>element with classicon - Verify role="img"` -- applied to meaningful icons so assistive technology treats the span as an image
- Verify aria-label="..."` -- provides the accessible name for meaningful icons
- Verify pass-through attributes are applied
Advice
- Designers: Ensure icons are visually clear at small sizes. Pair icons with text labels when the meaning may be ambiguous. Maintain consistent icon sizing across the interface.
- Developers: Set
decorative={true}when the icon is adjacent to a text label that conveys the same meaning. Always providelabelfor standalone icons.
Related components
icon-button— a button containing only an icon with a required accessible labelemoji— a single emoji character with accessible nameqr-code— a QR code image generated from text or URL data
References
- WAI-ARIA img role: https://www.w3.org/TR/wai-aria-1.2/#img
- WAI-ARIA Practices - Images: https://www.w3.org/WAI/tutorials/images/decorative/