Form and form controls

Accessible Form Labels #

Description:
Screen reader: NVDA
Video:

Form Validation and Error Handling #

Forms (edit field, radio button, drop-down, checkbox) #

Accessible forms are crucial to allow all users to interact with and submit information on websites independently. Implementing the following key elements ensures forms are fully usable and accessible, particularly for screen reader users.

  • Every form field has a clear and descriptive label that is announced by the screen reader.
  • The type of each field (e.g., text input, checkbox, radio button) is accurately identified and announced by the screen reader.
  • When a form error occurs, the error message must be communicated to the screen reader.
  • When an error is detected, the screen reader automatically moves focus to the relevant field so the user can easily correct the input.
  • The keyboard focus moves logically through the form fields.
  • Placeholders do not replace proper labels and are used in combination with labels to avoid confusion for screen reader users.
  • The submit button is clearly labeled and focusable, with the screen reader announcing its function correctly.
  • All form fields, buttons, and other interactive elements are fully navigable using the keyboard alone.
  • Required form fields should be clearly announced as such.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Accessible Form with ARIA Example</title>
    <script>
        function announceSubmission() {
            // Update live region with submission message
            const liveRegion = document.getElementById('form-status');
            liveRegion.textContent = "Form has been successfully submitted.";
        }
    </script>
</head>
<body>
    <h1>Accessible Form Example</h1>
    
    <!-- Live Region for Form Submission Announcement -->
    <div id="form-status" aria-live="polite" role="status" style="visibility: hidden;"></div>
    <form action="#" method="post" onsubmit="event.preventDefault(); announceSubmission();">
        
        <!-- Edit Field with ARIA -->
        <div>
            <label id="name-label" for="name">Full Name:</label>
            <input type="text" id="name" name="name" aria-labelledby="name-label" aria-required="true" required>
        </div>
        <!-- Radio Buttons with ARIA -->
        <fieldset>
            <legend id="gender-legend">Gender:</legend>
            <div>
                <input type="radio" id="gender-male" name="gender" value="male" aria-labelledby="gender-legend gender-male-label">
                <label id="gender-male-label" for="gender-male">Male</label>
            </div>
            <div>
                <input type="radio" id="gender-female" name="gender" value="female" aria-labelledby="gender-legend gender-female-label">
                <label id="gender-female-label" for="gender-female">Female</label>
            </div>
            <div>
                <input type="radio" id="gender-other" name="gender" value="other" aria-labelledby="gender-legend gender-other-label">
                <label id="gender-other-label" for="gender-other">Other</label>
            </div>
        </fieldset>
        <!-- Dropdown Menu with ARIA -->
        <div>
            <label id="country-label" for="country">Country:</label>
            <select id="country" name="country" aria-labelledby="country-label" aria-required="true">
                <option value="usa">United States</option>
                <option value="canada">Canada</option>
                <option value="uk">United Kingdom</option>
                <option value="australia">Australia</option>
            </select>
        </div>
        <!-- Checkboxes with ARIA -->
        <fieldset>
            <legend id="interest-legend">Select Your Interests:</legend>
            <div>
                <input type="checkbox" id="interest-tech" name="interest" value="tech" aria-labelledby="interest-legend interest-tech-label">
                <label id="interest-tech-label" for="interest-tech">Technology</label>
            </div>
            <div>
                <input type="checkbox" id="interest-sports" name="interest" value="sports" aria-labelledby="interest-legend interest-sports-label">
                <label id="interest-sports-label" for="interest-sports">Sports</label>
            </div>
            <div>
                <input type="checkbox" id="interest-music" name="interest" value="music" aria-labelledby="interest-legend interest-music-label">
                <label id="interest-music-label" for="interest-music">Music</label>
            </div>
        </fieldset>
        <!-- Submit Button -->
        <div>
            <button type="submit" aria-label="Submit the form">Submit</button>
        </div>
    </form>
</body>
</html>

Keyboard Navigation in Forms #

Description:
Screen reader: NVDA
Video:


Accessible Buttons #

Description:
Screen reader: NVDA
Video:

Radiobuttons:

Radio buttons are interactive form elements that allow users to select a single option from a predefined group of mutually exclusive choices. They are commonly used in scenarios where only one selection is allowed, such as choosing a payment method or selecting a delivery option.

To ensure radio buttons are inclusive and easy to use for screen reader users, it’s essential to follow these key accessibility practices.

  • Each radio button is implemented using the `<input type=”radio”>` element, paired with a `<label>` to provide a clear and descriptive name.
  • All radio buttons within a group share the same `name` attribute, ensuring they are treated as a group by screen readers.
  • The radio button group has a descriptive label, provided by a `<legend>` element when contained within a `<fieldset>`, or with `aria-labelledby` or `aria-label` if outside a fieldset.
  • Screen readers announce each radio button’s label, current selection state (e.g., “Selected”), and position in the group (e.g., “Option 1 of 3”).
  • For unselected radio buttons, screen readers announce “Not selected.”
  • Users can navigate through the radio buttons in the group using the arrow keys (up/down or left/right), with the selection changing as they move.
  • The Tab key moves focus into and out of the group but not between individual radio buttons.
  • Only one radio button in the group is focusable at a time, preventing confusion during navigation.
  • The focus indicator is clearly visible for sighted keyboard users.
  • Only one radio button in the group can be selected at any given time, and selecting a new option automatically deselects the previous one. 
  • Additional instructions or hints for the radio group are programmatically associated using `aria-describedby` to ensure screen readers can convey them.

What are your feelings

Updated on March 5, 2025