Lesson 3 of 9
ARIA Attributes Deep Dive
ARIA (Accessible Rich Internet Applications) attributes bridge gaps where native HTML semantics fall short. Learn when to use - and when NOT to use - ARIA roles, states, and properties.
ARIA Rules & Common Patterns
- Rule 1: Don't use ARIA if native HTML works - <button> is better than <div role='button'>
- Rule 2: Don't change native semantics - <h2 role='tab'> is wrong, use <button role='tab'>
- aria-label - Provides invisible label: <button aria-label='Close'>X</button>
- aria-hidden='true' - Hides element from screen readers while keeping it visible. Use for decorative icons
- aria-live='polite' - Announces dynamic content changes. 'polite' waits for pause, 'assertive' interrupts immediately
- role='alert' - Immediately announces content to screen reader. Use for error messages and notifications
- aria-expanded - Indicates whether a collapsible section is open: true/false. Toggle with JavaScript
- aria-describedby - Links an element to descriptive text. Used for form helper text and error messages
Tip
The first rule of ARIA is 'Don't use ARIA if native HTML can do the job.' A <button> element has built-in keyboard handling, ARIA role, and focus management. A <div role='button' tabindex='0'> needs all of that added manually and is more likely to have accessibility bugs.
ARIA supplements HTML semantics when native elements cannot convey full meaning
Quick Quiz: ARIA
Key Takeaways
- ARIA (Accessible Rich Internet Applications) attributes bridge gaps where native HTML semantics fall short.
- Rule 1: Don't use ARIA if native HTML works - <button> is better than <div role='button'>
- Rule 2: Don't change native semantics - <h2 role='tab'> is wrong, use <button role='tab'>
- aria-label - Provides invisible label: <button aria-label='Close'>X</button>
Finished this lesson?