Checkout form

Description: #

A checkout form is a critical part of any transactional site, as it involves users sharing sensitive information and completing an important transaction. Making the form accessible ensures that all users, including those with disabilities, can complete the purchase process confidently and without barriers. The following accessibility practices enhance the usability and inclusivity of the checkout experience.

  1. Clear Labels and Instructions:
    • Every input field should have a well-defined label that describes its purpose. Labels help all users understand what information is expected, especially for those using screen readers. For example, instead of only using placeholder text, each field should have a <label> tag for long-term visibility and screen reader compatibility.
    • Inline instructions, like format requirements for the credit card number or expiration date, should be placed near the relevant fields to prevent confusion.
  2. Field Grouping with Headings and Landmarks:
    • Group related fields, such as billing and payment information, using <fieldset> and <legend> tags. These elements improve navigation and make the form more understandable for screen reader users by allowing them to jump between grouped sections (e.g., “Billing Information” and “Payment Information”).
    • Headings and landmarks (e.g., role="main", role="form") also aid keyboard users and people using assistive technologies by providing a clear, structured flow.
  3. Error Prevention and Validation:
    • Implement error prevention by validating fields as the user types or before submission. For instance, check for empty required fields, invalid formats, or mismatched information. Provide descriptive, specific error messages near the input fields to guide users in correcting mistakes.
    • Use aria-live="assertive" on error messages to announce them immediately, ensuring screen reader users receive timely feedback without the need to search for errors manually. Each input should also have aria-describedby to link it to the error message, so when the field is revisited, the error information is clear.
  4. Keyboard Navigation and Focus Management:
    • Ensure the entire form is navigable via keyboard, maintaining a logical, sequential tab order for smooth interaction. Every input field, button, and link should be focusable.
    • Add a visible focus indicator (e.g., a highlighted border) to clearly indicate the currently focused field or button. This is essential for users who navigate forms using only the keyboard or other input devices besides a mouse.
  5. Accessible Notifications and Success Messages:
    • When a user submits the form successfully, provide immediate feedback with a polite notification that doesn’t disrupt their workflow. A live region with aria-live="polite" should be used for non-intrusive announcements, like confirmation messages, ensuring screen readers announce the message at a convenient pause in the user’s activity.
    • For real-time notifications, such as updating totals when a promo code is applied, use non-intrusive visual and auditory cues. This reassures users that their action was successful without interrupting their current task.
  6. Descriptive Button Labels and Consistent Styling:
    • Buttons should have clear, descriptive labels that indicate their purpose. Instead of generic labels like “Submit,” use specific actions like “Place Order” or “Continue to Payment.” This clarity benefits all users, especially those with cognitive disabilities who may struggle with ambiguous instructions.
    • Consistent button styling across the site helps users recognize interactive elements instantly, while descriptive labels ensure that screen reader users and those with cognitive disabilities understand each button’s purpose

Below is an accessible checkout form that incorporates these practices to improve usability and accessibility for all users.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Accessible Checkout Form</title>
    <style>
        .error-message {
            color: red;
            font-size: 0.9em;
        }
        .hidden {
            display: none;
        }
        .focusable:focus {
            outline: 3px solid #FFBF00;
        }
    </style>
    <script>
        function validateForm(event) {
            event.preventDefault();
            let valid = true;
            const nameField = document.getElementById('name');
            const emailField = document.getElementById('email');
            const cardField = document.getElementById('card-number');
            const nameError = document.getElementById('name-error');
            const emailError = document.getElementById('email-error');
            const cardError = document.getElementById('card-error');
            const successMessage = document.getElementById('success-message');
            nameError.classList.add('hidden');
            emailError.classList.add('hidden');
            cardError.classList.add('hidden');
            successMessage.classList.add('hidden');
            if (nameField.value.trim() === "") {
                nameError.classList.remove('hidden');
                nameError.setAttribute('aria-live', 'assertive');
                valid = false;
            }
            if (emailField.value.trim() === "") {
                emailError.classList.remove('hidden');
                emailError.setAttribute('aria-live', 'assertive');
                valid = false;
            }
            if (cardField.value.trim() === "") {
                cardError.classList.remove('hidden');
                cardError.setAttribute('aria-live', 'assertive');
                valid = false;
            }
            if (valid) {
                successMessage.classList.remove('hidden');
                successMessage.setAttribute('aria-live', 'polite');
            }
        }
    </script>
</head>
<body>
    <h1>Checkout Form</h1>
    <form onsubmit="validateForm(event)">
        <fieldset>
            <legend>Billing Information</legend>
            
            <label for="name">Full Name:</label>
            <input type="text" id="name" name="name" class="focusable" aria-describedby="name-error" required>
            <div id="name-error" class="error-message hidden">Please enter your full name.</div>
            
            <label for="email">Email:</label>
            <input type="email" id="email" name="email" class="focusable" aria-describedby="email-error" required>
            <div id="email-error" class="error-message hidden">Please enter a valid email address.</div>
        </fieldset>
        <fieldset>
            <legend>Payment Information</legend>
            
            <label for="card-number">Credit Card Number:</label>
            <input type="text" id="card-number" name="card-number" class="focusable" aria-describedby="card-error" required>
            <div id="card-error" class="error-message hidden">Please enter your credit card number.</div>
            
            <label for="expiry-date">Expiration Date:</label>
            <input type="text" id="expiry-date" name="expiry-date" class="focusable" placeholder="MM/YY" required>
        </fieldset>
        <button type="submit" class="focusable">Place Order</button>
    </form>
    <div id="success-message" class="hidden" role="status">
        Your order has been successfully placed!
    </div>
</body>
</html>

Key Takeaways #

  • Provide Clear Labels and Contextual Error Messages: Use <label> elements and aria-describedby to associate error messages with specific fields. Ensure that each error message is clear and specific to the issue.
  • Structure the Form with Fieldsets and Legends: Grouping related fields within <fieldset> and <legend> tags enhances navigation for screen reader users and makes form sections easier to identify.
  • Implement Error Validation and Notifications: Inline error messages should appear dynamically and use aria-live="assertive" to announce errors immediately. Non-intrusive success notifications, like aria-live="polite" announcements, provide clear feedback without disruption.
  • Keyboard Accessibility and Focus Indicators: Ensure that every element is keyboard accessible and provides a visible focus state, allowing users who rely on keyboard navigation to complete the form confidently.
  • Descriptive, Consistent Button Labels: Avoid vague labels like “Submit”; instead, use action-oriented language such as “Place Order.” This provides clarity for users of all abilities.

By adhering to these practices, you create a checkout form that is accessible.

What are your feelings

Updated on March 6, 2025