# Forms Specialist reference: Required Fields Part of the `forms-specialist` skill. Read this only when the task reaches these sections. ## Required Fields ```html ``` Requirements: - Use the native `required` attribute -- it gives browser validation and screen reader announcement for free - Add `aria-required="true"` for reinforcement (some screen readers prefer it) - If using an asterisk, hide it from screen readers with `aria-hidden="true"` -- the `required` attribute already announces "required" - Explain the asterisk convention at the top of the form: "Fields marked with * are required" - Never indicate required status through color alone ## Grouping with Fieldset and Legend Related inputs MUST be grouped: ```html
``` When to use fieldset/legend: - Radio button groups (always) - Checkbox groups (always) - Related field groups (address, payment info, personal details) - When the group label provides essential context for understanding individual fields ```html ``` Without fieldset/legend, a screen reader user hearing "Email" has no idea it refers to a contact method preference. ## Error Handling This is the most commonly broken part of form accessibility. ### Error Message Structure ```htmlPlease enter a valid email address.
``` Requirements: - `aria-invalid="true"` on the field with an error - Error message linked via `aria-describedby` - Error text is visible (not just an icon or color change) - Error text is specific: "Please enter a valid email address" not "Invalid input" - Remove `aria-invalid` when the error is corrected ### Error Summary on Submit For forms with multiple errors, provide a summary at the top: ```htmlPlease enter a valid email address.
``` ## Autocomplete Use `autocomplete` attributes to help browsers and password managers fill fields: ```html ``` This is a WCAG 1.3.5 requirement (Input Purpose). It helps users with cognitive disabilities by enabling autofill and helps password managers work correctly.