UI Components Accessibility Best Practices
| Best Practice | Description |
|---|---|
| Keyboard Accessibility | Ensure that all actions and functionality can be performed using only a keyboard. |
| Visible Focus States | Ensure that links, buttons, and controls have a clearly visible focus state. |
| Text Alternatives | Present all content as text or provide a text equivalent (e.g., alt text for SVGs, aria-label for meaningful icons). |
| Dynamic State Announcements | Ensure that changes in a component’s state (e.g., toggling aria-expanded from “false” to “true”) are announced by screen readers. |
| Sufficient Color Contrast | Use color combinations that have sufficient contrast for readability. |
Buttons
- Accessible Name: Use visible text or provide an
aria-labelfor buttons so that screen readers announce their purpose. - Keyboard Operability: Ensure buttons can be activated via keyboard events (e.g., Enter, Space).
- State Management: Use ARIA attributes such as
aria-pressedfor toggle buttons, and disable buttons using both the nativedisabledattribute andaria-disabled.
Links
- Descriptive Text: Ensure links have clear, descriptive text that explains their destination or purpose.
- Icon-Only Links: When using icons alone, provide an
aria-labelor include visually hidden text. - External Links: Use
target="_blank"withrel="noopener noreferrer"for security when linking externally.
Modals
- Role & Attributes: Use
role="dialog"(oralertdialog) andaria-modal="true"to indicate the presence of a modal dialog. - Title Association: Link the modal title to the dialog with
aria-labelledby. - Keyboard Handling: Trap focus within the modal and allow closing via the Escape key.
- Backdrop Interaction: Allow the modal to be dismissed by clicking the backdrop, with clear instructions provided if needed.
Toast Notifications
- Alert Role: Use
role="alert"andaria-live="assertive"so that toast messages are announced immediately. - Dismissibility: Provide a clear way to dismiss the toast, with a dismiss button that has an appropriate
aria-label.
Tags and Labels
- Contrast and Legibility: Ensure text and background colors have sufficient contrast for readability.
- Accessible Naming: For non-interactive tags, the visible text is typically sufficient; consider an
aria-labeloverride if needed.