Skip to main content

Accessibility UI Guidelines: Forms

Forms

2.2 Forms

Creating accessible forms is crucial to ensure that all users, including those with disabilities, can interact with and complete forms effectively. This section outlines various accessibility challenges and provides solutions to address them, covering neurological, psychological, visual, auditory, and other considerations.

2.2.1 Proper Labeling of Form Elements

All form controls must have associated labels to ensure that users with screen readers can understand the purpose of each input field.

  • Use <label> elements linked to their corresponding form controls using the for attribute.
  • Ensure that labels are descriptive and concise.
<form>
    <label for="email">Email Address:</label>
    <input type="email" id="email" name="email" required>

    <label for="password">Password:</label>
    <input type="password" id="password" name="password" required>

    <button type="submit">Submit</button>
</form>

2.2.2 Keyboard Navigation

Ensure that all form elements are accessible via keyboard to support users with motor disabilities.

  • Maintain a logical tab order.
  • Ensure that custom form controls are focusable and operable using the keyboard.
<form>
    <label for="search">Search:</label>
    <input type="text" id="search" name="search">

    <button type="submit">Go</button>
</form>

2.2.3 Clear Error Identification and Description

Provide clear and accessible error messages to help users understand and correct their mistakes.

  • Consider aria-describedby to associate error messages with the relevant input fields.
  • Consider aria-live if the page updates live. If in doubt, refer to the documentation first.
  • Ensure error messages are specific and actionable.
<form>
    <label for="username">Username:</label>
    <input type="text" id="username" name="username" aria-describedby="username-error" required>
    <span id="username-error" role="alert">Username is required and must be at least 6 characters.</span>

    <button type="submit">Register</button>
</form>

2.2.4 Grouping Related Form Elements

Use <fieldset> and <legend> to group related form controls, enhancing comprehension for all users, including those with cognitive disabilities.

  • Group related inputs within a <fieldset>.
  • Provide a <legend> that describes the group.
<form>
    <fieldset>
        <legend>Personal Information</legend>

        <label for="first-name">First Name:</label>
        <input type="text" id="first-name" name="first-name" required>

        <label for="last-name">Last Name:</label>
        <input type="text" id="last-name" name="last-name" required>
    </fieldset>

    <button type="submit">Submit</button>
</form>

2.2.5 Accessible Form Validation

Implement validation that is accessible to all users, providing real-time feedback without causing confusion or frustration.

  • Use ARIA roles and properties to convey validation status.
  • Provide both visual and programmatic feedback.
<form>
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" aria-invalid="false" aria-describedby="email-error" required>
    <span id="email-error" role="alert" hidden>Please enter a valid email address.</span>

    <button type="submit">Submit</button>
</form>

<script>
    const emailInput = document.getElementById('email');
    const emailError = document.getElementById('email-error');

    emailInput.addEventListener('input', () => {
        if (emailInput.validity.valid) {
            emailInput.setAttribute('aria-invalid', 'false');
            emailError.hidden = true;
        } else {
            emailInput.setAttribute('aria-invalid', 'true');
            emailError.hidden = false;
        }
    });
</script>

2.2.6 Instructions and Help Text

Provide clear instructions and help text to guide users through the form, especially those with cognitive or neurological disabilities.

  • Place instructions near relevant form fields.
  • Use simple and straightforward language.
<form>
    <label for="phone">Phone Number:</label>
    <input type="tel" id="phone" name="phone" aria-describedby="phone-help" required>
    <p id="phone-help">Format: +1 (123) 456-7890</p>

    <button type="submit">Submit</button>
</form>

2.2.7 Accessible Captchas

Ensure that captchas are accessible to users with visual or cognitive impairments by providing alternative methods.

  • Use audio captchas.
  • Implement logic-based or mathematical captchas.
  • Provide alternative verification methods.
<form>
    <!-- Visual Captcha -->
    <label for="captcha">Enter the text shown:</label>
    <img src="captcha-image.png" alt="Captcha image showing random characters">
    <input type="text" id="captcha" name="captcha" required>

    <!-- Audio Captcha Alternative -->
    <a href="audio-captcha.mp3">Listen to captcha</a>

    <button type="submit">Submit</button>
</form>

2.2.8 Time Limits

Avoid imposing strict time limits on form completion or provide options to extend the time to accommodate users with cognitive or neurological disabilities.

  • If a time limit is necessary, allow users to request more time.
  • Provide warnings before the time expires.
<form id="secure-form">
    <!-- Form fields go here -->
    <button type="submit">Submit</button>
</form>

<script>
    let timeLeft = 300; // 5 minutes
    const timer = setInterval(() => {
        if (timeLeft <= 0) {
            clearInterval(timer);
            alert('Your session has expired. Please reload the page to start again.');
            document.getElementById('secure-form').reset();
        } else {
            timeLeft--;
            // Optionally display the timer to the user
        }
    }, 1000);
</script>

2.2.9 Sufficient Color Contrast and Visual Design

Ensure that form elements have sufficient color contrast and are designed to be easily distinguishable for users with visual impairments.

  • Use high-contrast color schemes.
  • Avoid relying solely on color to convey information.
<form>
    <label for="age">Age:</label>
    <input type="number" id="age" name="age" required style="border: 2px solid #000;">

    <button type="submit" style="background-color: #005A9C; color: #FFFFFF;">Submit</button>
</form>

2.2.10 Accessible Date Pickers and Other Widgets

Use accessible widgets or provide alternatives to ensure that all users can interact with form controls.

  • Use native HTML5 input types when possible.
  • Provide keyboard-accessible custom widgets.
  • Offer alternative input methods.
<form>
    <label for="birthday">Birthday:</label>
    <input type="date" id="birthday" name="birthday" required>

    <button type="submit">Submit</button>
</form>

2.2.11 Assistive Technology Compatibility

Ensure that forms are compatible with various assistive technologies, such as screen readers and voice recognition software.

  • Use semantic HTML elements.
  • Test forms with different assistive technologies.
  • Avoid using inaccessible custom controls.
<form>
    <label for="feedback">Your Feedback:</label>
    <textarea id="feedback" name="feedback" aria-label="Feedback form" required></textarea>

    <button type="submit">Submit</button>
</form>

2.2.12 Support for Cognitive Disabilities

Design forms to be simple and easy to understand, reducing cognitive load for users with cognitive or neurological disabilities.

  • Use clear and concise instructions.
  • Break long forms into manageable sections.
  • Use consistent layouts and labeling.
<form>
    <fieldset>
        <legend>Account Information</legend>

        <label for="username">Username:</label>
        <input type="text" id="username" name="username" required>

        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required>
    </fieldset>

    <fieldset>
        <legend>Contact Information</legend>

        <label for="email">Email Address:</label>
        <input type="email" id="email" name="email" required>

        <label for="phone">Phone Number:</label>
        <input type="tel" id="phone" name="phone">
    </fieldset>

    <button type="submit">Register</button>
</form>

2.2.13 Responsive and Mobile-Friendly Design

Ensure that forms are accessible and usable on various devices, including mobile phones and tablets.

  • Use responsive design techniques.
  • Ensure touch targets are adequately sized.
  • Maintain readability on smaller screens.
<form style="max-width: 600px; margin: auto;">
    <label for="full-name">Full Name:</label>
    <input type="text" id="full-name" name="full-name" required style="width: 100%; padding: 8px;">

    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required style="width: 100%; padding: 8px;">

    <button type="submit" style="width: 100%; padding: 10px; background-color: #28a745; color: #fff;">Submit</button>
</form>

2.2.14 Multi-Step Forms Accessibility

For forms that span multiple steps, ensure that users can navigate between steps seamlessly and understand their progress.

  • Indicate the current step and total steps.
  • Allow users to navigate back to previous steps.
  • Preserve user input when navigating between steps.
<form id="multi-step-form">
    <div class="step" id="step-1" aria-labelledby="step-1-title">
        <h2 id="step-1-title">Step 1 of 3: Personal Information</h2>
        <label for="first-name">First Name:</label>
        <input type="text" id="first-name" name="first-name" required>
        <button type="button" onclick="showStep(2)">Next</button>
    </div>

    <div class="step" id="step-2" aria-labelledby="step-2-title" hidden>
        <h2 id="step-2-title">Step 2 of 3: Contact Information</h2>
        <label for="email">Email:</label>
        <input type="email" id="email" name="email" required>
        <button type="button" onclick="showStep(1)">Back</button>
        <button type="button" onclick="showStep(3)">Next</button>
    </div>

    <div class="step" id="step-3" aria-labelledby="step-3-title" hidden>
        <h2 id="step-3-title">Step 3 of 3: Confirmation</h2>
        <p>Please review your information before submitting.</p>
        <button type="button" onclick="showStep(2)">Back</button>
        <button type="submit">Submit</button>
    </div>
</form>

<script>
    function showStep(step) {
        document.querySelectorAll('.step').forEach((div) => div.hidden = true);
        document.getElementById(`step-${step}`).hidden = false;
    }
</script>

2.2.15 Accessible Dropdowns and Select Menus

Ensure that dropdowns and select menus are accessible to all users, including those using assistive technologies.

  • Use native <select> elements when possible.
  • If custom dropdowns are necessary, ensure they are keyboard accessible and properly labeled.
<form>
    <label for="country">Country:</label>
    <select id="country" name="country" required>
        <option value="">Select your country</option>
        <option value="uk">United Kingdom</option>
        <option value="usa">United States</option>
        <option value="Australia">Australia</option>
    </select>

    <button type="submit">Submit</button>
</form>

2.2.16 Accessible Radio Buttons and Checkboxes

Ensure that radio buttons and checkboxes are properly labeled and grouped for clarity and ease of use.

  • Use <fieldset> and <legend> to group related radio buttons or checkboxes.
  • Associate each input with a <label>.
<form>
    <fieldset>
        <legend>Preferred Contact Method</legend>

        <div>
            <input type="radio" id="contact-email" name="contact-method" value="email" required>
            <label for="contact-email">Email</label>
        </div>

        <div>
            <input type="radio" id="contact-phone" name="contact-method" value="phone">
            <label for="contact-phone">Phone</label>
        </div>
    </fieldset>

    <fieldset>
        <legend>Interests</legend>

        <div>
            <input type="checkbox" id="interest-news" name="interests" value="news">
            <label for="interest-news">News</label>
        </div>

        <div>
            <input type="checkbox" id="interest-updates" name="interests" value="updates">
            <label for="interest-updates">Product Updates</label>
        </div>
    </fieldset>

    <button type="submit">Submit</button>
</form>

2.2.17 Accessible File Uploads

Ensure that file upload controls are accessible and provide clear instructions for users who may have difficulties.

  • Use descriptive labels.
  • Provide instructions on acceptable file types and sizes.
  • Ensure that file upload controls are keyboard accessible.
<form>
    <label for="cv">Upload Your CV:</label>
    <input type="file" id="cv" name="cv" accept=".pdf, .doc, .docx" required>
    <small>Accepted formats: PDF, DOC, DOCX. Maximum size: 2MB.</small>

    <button type="submit">Submit</button>
</form>

2.2.18 Accessible Buttons and Submission Controls

Ensure that buttons and submission controls are clearly labeled and accessible to all users.

  • Use descriptive text on buttons.
  • Ensure buttons are keyboard accessible and have sufficient touch target sizes.
<form>
    <!-- Form fields go here -->
    <button type="submit">Register Account</button>
</form>

2.2.19 Multi-Language Support

Provide support for multiple languages to accommodate users who speak different languages, enhancing accessibility for non-native speakers.

  • Use the lang attribute to specify the language of form elements.
  • Ensure that instructions and error messages are available in the user's preferred language.
<form lang="en">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required>

    <button type="submit">Submit</button>
</form>

<form lang="es">
    <label for="nombre">Nombre:</label>
    <input type="text" id="nombre" name="nombre" required>

    <button type="submit">Enviar</button>
</form>

2.2.20 Privacy and Security Considerations

Ensure that forms respect user privacy and communicate security measures clearly, which is particularly important for users with psychological concerns regarding data security.

  • Use HTTPS to encrypt data transmission.
  • Provide clear privacy policies and data handling information.
  • Indicate required fields and data usage transparently.
<form action="https://example.com/submit" method="POST">
    <label for="email">Email Address:</label>
    <input type="email" id="email" name="email" required>

    <p>We respect your privacy. Your information will be kept secure and will not be shared.</p>

    <button type="submit">Subscribe</button>
</form>

2.2.21 Financial Accessibility

Ensure that payment systems are inclusive and accessible, addressing diverse financial, technological, and disability-related barriers to enable all users to complete transactions with ease.

  • Provide diverse payment options, including credit cards, digital wallets, regional methods, and offline alternatives.
  • Display all costs upfront, including taxes and fees, to prevent confusion and ensure transparency.
  • Offer flexible payment plans, discounts, or trials to accommodate users with financial constraints.
  • Ensure payment forms are accessible with screen readers, keyboards, and assistive technologies.
  • Support representatives making payments on behalf of others where necessary.
<form action="https://example.com/payment" method="POST">
    <label for="payment-method">Select Payment Method:</label>
    <select id="payment-method" name="payment-method" required>
        <option value="credit-card">Credit Card</option>
        <option value="paypal">PayPal</option>
        <option value="bank-transfer">Bank Transfer</option>
        <option value="cash-on-delivery">Cash on Delivery</option>
    </select>

    <p>All fees are shown upfront. No hidden costs. Payments are secure and inclusive.</p>

    <button type="submit">Proceed to Payment</button>
</form>