Frontend Accessibility

Implement accessible React components with ARIA, keyboard navigation, and WCAG compliance.

1|Updated Dec 4, 2024
One-click install
npx skills add https://github.com/imkdw/imkdw-dev --skill frontend-accessibility-imkdw
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Frontend Accessibility
Source: https://github.com/imkdw/imkdw-dev/tree/main/.claude/skills/frontend-accessibility
Command: npx skills add https://github.com/imkdw/imkdw-dev --skill frontend-accessibility-imkdw

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Inaccessible user interfaces exclude users with disabilities, leading to a poor experience, reduced user base, and potential legal issues. This Skill guides the creation of inclusive and usable frontend components that adhere to WCAG guidelines.

Core Features & Use Cases

  • Semantic HTML: Prioritize meaningful HTML elements (nav, main, button) over generic divs, conveying structure and meaning to assistive technologies.
  • Keyboard Navigation & Focus: Ensure all interactive elements are fully operable via keyboard, with clear visual focus indicators, for users who don't use a mouse.
  • Screen Reader Support: Provide descriptive alt text for images, aria-label for icon-only buttons, and aria-live regions for dynamic content updates, enhancing the experience for screen reader users.
  • Use Case: When developing a new modal dialog, ensure it traps keyboard focus, returns focus to the trigger element on close, and has appropriate ARIA labels for screen readers, making it fully navigable and understandable for all users.

Quick Start

Review this button component and suggest improvements for keyboard accessibility and screen reader support, ensuring it has an aria-label for its icon and a visible focus-visible style.

Frequently Asked Questions about Frontend Accessibility

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make React components keyboard accessible?

Keyboard accessibility in React requires semantic HTML elements, focus management, and keyboard event handlers. Use native `<button>` and `<input>` tags instead of divs, implement `onKeyDown` handlers for custom interactions, manage focus with `useRef`, and add `tabIndex` where needed. Test navigation with Tab, Enter, and arrow keys to ensure all interactive elements are reachable and operable.

What WCAG guidelines should I follow for frontend UI components?

WCAG guidelines require semantic HTML structure, keyboard operability, sufficient color contrast (4.5:1 for text), descriptive alt text for images, and ARIA labels for screen readers. Implement focus indicators, avoid relying solely on color to convey information, provide skip links, and use `aria-live` regions for dynamic content. These standards ensure compliance and improve usability for all users.

How do I implement ARIA attributes in Next.js and React components?

Add ARIA attributes directly to JSX elements: use `aria-label` for icon-only buttons, `aria-describedby` for descriptions, `aria-live` for dynamic updates, and `role` to clarify element semantics. In modals, apply `aria-modal="true"` and `aria-labelledby` to link the heading. Combine with semantic HTML—ARIA supplements but doesn't replace proper element choice.

How do I ensure focus management in accessible modals and dialogs?

Focus management requires trapping keyboard focus within the modal so Tab cycles only through focusable elements inside. On open, move focus to the first interactive element or modal heading. On close, return focus to the trigger button. Use `useRef` to manage focus programmatically, disable focus outside the modal with `inert`, and test with screen readers and keyboard navigation.

Can I use Radix UI or Headless UI for accessible components?

Yes. Radix UI and Headless UI are built with accessibility as a core feature, providing semantic HTML, keyboard navigation, ARIA attributes, and focus management out of the box. Both work seamlessly with React and Next.js. Using these primitives as a foundation reduces the work needed to meet WCAG standards and ensures consistent, tested accessible patterns.

What's the difference between semantic HTML and generic divs for accessibility?

Semantic HTML elements like `<nav>`, `<main>`, `<button>`, and `<input>` convey meaning and structure to assistive technologies, enabling screen readers to announce element types and relationships. Generic `<div>` elements require custom ARIA roles and attributes to communicate the same meaning. Semantic HTML is simpler, more performant, and the accessible-first approach.