Validation States
Validation states provide visual feedback to users about the validity of form input.
Use the aria-invalid attribute to indicate validation state:
aria-invalid="true"— Indicates the field has failed validationaria-invalid="false"— Indicates the field has passed validation
Pair with aria-describedby to link helper text that explains the validation result:
html
<input
type="email"
aria-invalid="true"
aria-describedby="email-error"
/>
<small id="email-error">Please enter a valid email address.</small>Form Validation Example
live preview
editable html
<form>
<fieldset>
<label>
Email address
<input
type="email"
name="email"
placeholder="user@example.com"
aria-invalid="false"
aria-describedby="email-helper"
required
/>
<small id="email-helper">We'll never share your email with anyone else.</small>
</label>
<label>
Password
<input
type="password"
name="password"
aria-invalid="true"
aria-describedby="password-helper"
required
/>
<small id="password-helper">Password must be at least 8 characters long.</small>
</label>
</fieldset>
<input type="submit" value="Sign Up" />
</form>
INFO
The <small> element associated with a form control via aria-describedby automatically inherits the validation state colors.
Best Practices
Accessibility First
- Always use
aria-invalidto communicate state to assistive technologies - Pair with
aria-describedbyto provide context for the validation state - Ensure error messages are clear and actionable
Visual Feedback
- Use the
:invalidand:validpseudo-classes for native HTML5 validation - Combine with
aria-invalidfor JavaScript-driven validation - Helper text (
<small>) below form controls inherits validation colors automatically
Progressive Enhancement
- Start with HTML5 validation attributes (
required,type,pattern) - Enhance with JavaScript validation for complex rules
- Use
aria-invalidto communicate custom validation results
Reference
For detailed implementation of aria-invalid on specific elements, see the [aria-invalid] documentation.