--- name: angular-accessibility description: Enforce and improve accessibility (a11y) in Angular applications following WCAG 2.2 AA, ARIA best practices, semantic HTML, and Angular-specific patterns. --- # Angular Accessibility Skill ## Purpose This skill helps build and review Angular applications that are accessible by default. It prioritizes semantic HTML, keyboard navigation, screen reader compatibility, color contrast, focus management, and Angular CDK accessibility utilities. Target standard: **WCAG 2.2 Level AA** ## When to Use Activate this skill whenever the task involves: - Creating Angular components - Reviewing templates for accessibility - Refactoring UI components - Building forms - Navigation menus - Dialogs and modals - Tables - Custom controls - Angular Material components - Accessibility audits - Fixing Lighthouse or axe-core accessibility issues --- # Accessibility Principles Always follow this priority order: 1. Semantic HTML 2. Native browser behavior 3. Angular accessibility utilities 4. ARIA only when necessary **Rule:** Never use ARIA to replace native HTML functionality. Example: Good: ```html ``` Avoid: ```html
Save
``` --- # Angular Template Rules ## Buttons Always: - use ` ``` Icon button: ```html ``` --- ## Links Use `` only for navigation. Good: ```html Dashboard ``` Avoid: ```html Save ``` Use a button instead. --- ## Images Decorative: ```html ``` Informative: ```html Jane Doe smiling ``` Avoid generic alt text like "image" or "photo." --- # Forms ## Labels Every input needs a label. Good: ```html ``` Angular Material: ```html Email ``` --- ## Error Messages Requirements: - visible - descriptive - associated with the input Example: ```html
Enter a valid email address.
``` Avoid relying on color alone. --- ## Required Fields Use both: ```html ``` --- # Keyboard Accessibility Every interactive element must be usable with: - Tab - Shift+Tab - Enter - Space - Escape (when applicable) - Arrow keys (where expected) Never trap keyboard focus. --- # Focus Management Use Angular CDK when possible. Example: ```typescript constructor(private focusMonitor: FocusMonitor) {} ``` For dialogs: - move focus into dialog - trap focus - restore focus on close Angular Material already provides this behavior. --- # Angular CDK Accessibility Prefer Angular CDK utilities. Useful services: - FocusMonitor - LiveAnnouncer - InteractivityChecker - FocusTrapFactory Example: ```typescript this.liveAnnouncer.announce('Settings saved'); ``` Use for: - success messages - validation updates - dynamic content --- # ARIA Usage Use ARIA only when native HTML cannot express the behavior. Common attributes: | Attribute | Use | |-----------|-----| | aria-label | Icon buttons | | aria-labelledby | Existing visible label | | aria-describedby | Helper/error text | | aria-expanded | Expandable controls | | aria-controls | Controlled region | | aria-live | Dynamic announcements | | aria-current | Current navigation item | Avoid redundant ARIA. Bad: ```html