Accessible Icon
Utilities
Accessibility
Makes icons accessible by providing a text alternative for screen readers. Essential for icon-only buttons and meaningful icons.
Preview
Icons with accessible labels
With Icon Buttons
Proper accessibility for icon-only buttons
Navigation Icons
Accessible icons in navigation
HomeSettingsProfile
Status Icons
Icons conveying status information
Operation completed successfully
Please review before continuing
When to Use
Guidelines for using AccessibleIcon
Use AccessibleIcon when:
- Icon is the only content in a button or link
- Icon conveys important information or status
- Icon represents an interactive action
- Icon is part of navigation or wayfinding
Skip AccessibleIcon when:
- Icon is purely decorative (use aria-hidden="true" instead)
- Visible text already describes the icon
- Icon duplicates adjacent text content
Props
AccessibleIcon API reference
| Prop | Type | Default | Description |
|---|---|---|---|
label* | string | — | The accessible text alternative for screen readers |
children* | React.ReactNode | — | The icon element to make accessible |
Usage
Import and implementation examples
import { AccessibleIcon } from '@/components/ui/accessible-icon'import { Settings, X, Heart } from 'lucide-react'
// Basic usage<AccessibleIcon label="Settings"> <Settings className="w-5 h-5" /></AccessibleIcon>
// In an icon-only button<button> <AccessibleIcon label="Close dialog"> <X className="w-4 h-4" /> </AccessibleIcon></button>
// With Button component<Button size="icon" variant="ghost"> <AccessibleIcon label="Add to favorites"> <Heart className="w-4 h-4" /> </AccessibleIcon></Button>
// Decorative icon (no AccessibleIcon needed)<span aria-hidden="true"> <Settings className="w-4 h-4" /></span>Visible Settings LabelFeatures
Built-in functionality
- Screen reader support: Label announced to assistive technologies
- Visually hidden text: Label hidden from sighted users
- Radix primitive: Built on tested accessibility patterns
- Zero styling: Pure accessibility utility, no visual changes
- Simple API: Just wrap your icon with a label
Accessibility
Accessibility features
ARIA Attributes
Renders a visually hidden span with the label textIcon inherits aria-hidden="true" automaticallyLabel is announced by screen readersKeyboard Navigation
| Key | Action |
|---|---|
| N/A | Not interactive - parent element handles focus |
Notes
- Always provide descriptive, actionable labels
- Labels should describe the action, not the icon appearance
- Bad: "X icon" - Good: "Close dialog"
- Bad: "Heart" - Good: "Add to favorites"