Skip to main content
InterviewHubPRO
Section Overview
Q17

Question 17 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

34%
Web Accessibility & WCAG (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

How do you implement Accessible Form Validation?

senior LevelCode ExampleFormsSystem Design

In Simple Words: When an input fails validation:

  1. Set aria-invalid="true" on the input.
  2. Link the error message element to the input using aria-describedby:
html
<label for="user-age">Age:</label>
<input id="user-age"
       type="number"
       aria-invalid="true"
       aria-describedby="age-error-msg" />
<span id="age-error-msg" role="alert" class="error-text">
  You must be at least 18 years old.
</span>

When focus lands on the input, the screen reader announces: "Age, edit text, invalid entry. You must be at least 18 years old."