Building Accessible Forms & Modals: 5 Practical Rules for Modern Web Apps
From visible focus rings to dynamic error announcements: How to build high-converting forms that work flawlessly for keyboard and screen reader users.
Forms and modal dialogs represent the most critical conversion checkpoints on any digital product. When accessibility fails here, sign-ups drop and checkouts stall.
Here are 5 core rules to make forms and modals accessible for all users.
1. Always Link Explicit <label> Elements
Placeholders disappear when typing begins and fail to provide permanent context for screen readers.
<label for="checkout-email" class="block text-sm font-bold">
Email Address <span aria-hidden="true">*</span>
</label>
<input id="checkout-email" type="email" required autocomplete="email" />
2. Announce Validation Errors with aria-describedby
When validation fails, link the input directly to the error message container using aria-describedby and set aria-invalid="true".
3. Trap and Restore Focus in Modals
- Move focus to the first interactive element or dialog heading on open.
- Ensure
TabandShift+Tabcycle strictly inside the modal container. - On pressing
Escape, close the modal and restore focus to the triggering button.
4. Never Strip Focus Rings without a Custom Replacement
Use modern :focus-visible to style focus indicators beautifully without harming mouse users:
button:focus-visible {
outline: 2px solid #0D9488;
outline-offset: 3px;
border-radius: 8px;
} Is your website compliant with WCAG 2.2?
Scan your site for free with the Wabiy live engine and uncover barriers instantly.