Tailwind CSS Accessibility
Accessibility utilities in Tailwind CSS enhance usability by ensuring compatibility with assistive technologies like screen readers and high-contrast modes. These utilities help developers create inclusive designs that adhere to accessibility best practices while maintaining a consistent UI experience.
Tailwind provides sr-only
for screen readers and forced-color-adjust-*
for handling high-contrast environments, ensuring content remains readable and usable across different user settings and devices.
Utility | Description | Example |
---|---|---|
Screen Readers | Hides elements visually while remaining accessible to screen readers. | <span className="sr-only">Accessible text</span> |
Forced Color Adjust | Controls color adjustments in high contrast mode environments. | <div className="forced-color-adjust-auto"></div> |
Best Practices
Ensure Assistive Technology
The sr-only
utility hides content visually but keeps it available for screen readers. This is useful for providing extra context or instructions that should not be visible to sighted users. For better accessibility, use sr-only
on descriptive labels or additional information that enhances navigation for visually impaired users.
Make Hidden Content Visible
The not-sr-only
utility restores visibility to previously hidden screen reader content, improving usability for interactive elements. For skip links or accessibility hints, applying focus:not-sr-only
ensures content is only revealed when necessary.
Handle High-Contrast Mode
The forced-color-adjust-*
utility prevents browsers from automatically adjusting colors in high-contrast mode. Applying forced-color-adjust-none
ensures that the UI retains its intended color scheme in environments where forced color settings are enabled. For design consistency, test high-contrast compatibility and apply forced-color-adjust-auto
where needed to let the browser handle color adaptations dynamically.