Best practices for creating accessible, keyboard-navigable components that work for everyone. WCAG 2.1 AA compliance made practical.
June 10, 2026
Accessibility is not optional—it's essential for creating inclusive web applications.
Always use the correct HTML elements:
<!-- Good -->
<button>Click me</button>
<!-- Bad -->
<div onclick="handleClick()">Click me</div>
When HTML isn't enough, use ARIA:
<div
role="dialog"
aria-modal="true"
aria-labelledby="dialog-title"
aria-describedby="dialog-description"
<blockquote><p></p></blockquote>
<h2 id="dialog-title">Confirm Action</h2>
<p id="dialog-description">Are you sure?</p>
</div>
Ensure all interactive elements are keyboard accessible:
function CustomButton() {
return (
<div
tabindex="0"
role="button"
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
handleClick();
}
}}
onClick={handleClick}
>
Custom Button
</div>
);
}
Manage focus for modals and dynamic content:
import { useEffect, useRef } from "react";
function Modal({ isOpen, onClose }) {
const modalRef = useRef(null);
useEffect(() => {
if (isOpen && modalRef.current) {
modalRef.current.focus();
}
}, [isOpen]);
return (
<div ref={modalRef} tabindex="-1">
{/* Modal content */}
</div>
);
}
Use these tools:
Building accessible components from the start is easier than retrofitting accessibility later. Make it a habit!