LEARNING OBJECTIVES โต
- Implement WCAG 1.3.5 (Identify Input Purpose) compliance using standardized
autocompletetokens (shipping given-name,address-line1,postal-code,cc-number). - Utilize the HTML5 Constraint Validation API (
checkValidity(),reportValidity(),setCustomValidity()) to build accessible form verification without intrusive alerts. - Build a top-level accessible Error Summary component (
<div role="alert">) that shifts keyboard focus dynamically to invalid form fields upon submission. - Format and mask credit card numbers and expiration dates with
inputmode="numeric"and regex pattern constraints.
๐ The Mental Model & Story (Intuitive Foundation)
Imagine walking up to the customs declaration desk at an international airport. The border agent hands you a clipboard with a five-page form.
- The form has tiny illegible boxes.
- There is no indication of whether your home address needs a postal code or country code.
- When you hand the form back, the agent stamps a giant red "REJECTED" across the page without telling you what went wrong, forcing you to start over from scratch at the back of a two-hour line.
In e-commerce, the Checkout Form is that customs desk.
Over 70% of digital shopping carts are abandoned during the final checkout stage. The overwhelming majority of drop-offs occur because of friction: form fields that don't trigger mobile numeric keypads, autofill failures that scramble shipping addresses, and cryptic red border highlights that fail to explain what error occurred to a screen reader user.
An accessible, high-performance checkout form respects the customer's time and cognitive load. It supports browser autofill with standardized tokens, invokes mobile numeric keyboards with inputmode="numeric", validates fields smoothly, and provides immediate, polite error explanations.
Technical Deep Dive & Specifications
Standard WCAG 1.3.5 Autocomplete Tokens for E-Commerce
To satisfy WCAG 2.2 Level AA (Success Criterion 1.3.5), browsers and password managers (1Password, Apple Keychain, Google Autofill) require exact token strings:
| Field Purpose | Standard HTML autocomplete Value |
Recommended inputmode |
pattern Regex Example |
|---|---|---|---|
| Customer Full Name | autocomplete="name" |
text |
โ |
| Email Address | autocomplete="email" |
email |
Standard HTML5 type="email" |
| Shipping Address Line 1 | autocomplete="shipping address-line1" |
text |
โ |
| Shipping City / Locality | autocomplete="shipping address-level2" |
text |
โ |
| Shipping State / Province | autocomplete="shipping address-level1" |
text |
โ |
| Postal / ZIP Code | autocomplete="shipping postal-code" |
numeric or text |
^[0-9]{5}(-[0-9]{4})?$ (US) |
| Credit Card Number | autocomplete="cc-number" |
numeric |
^[0-9]{13,19}$ |
| Card Expiration (MM/YY) | autocomplete="cc-exp" |
numeric |
`^(0[1-9] |
| Card Security Code (CVV) | autocomplete="cc-csc" |
numeric |
^[0-9]{3,4}$ |
+----------------------------------------------------------------------------------------------------+
| ACCESSIBLE FORM ERROR SUMMARY WORKFLOW |
+----------------------------------------------------------------------------------------------------+
| |
| User clicks [ Complete Purchase ] |
| โ |
| โผ |
| Form Submit Intercepted (`novalidate` on <form>) |
| โ |
| โโโ 1. Iterate over form controls with form.elements |
| โโโ 2. Test validity with field.checkValidity() |
| โโโ 3. If invalid: |
| โ - Mark input: aria-invalid="true" |
| โ - Associate error message: aria-describedby="error-[id]" |
| โ - Collect errors into Error Summary array |
| โ |
| โผ |
| Render Error Summary in `<div role="alert" tabindex="-1">` at top of form |
| โ |
| โผ |
| Programmatically move focus to Error Summary: `summaryContainer.focus()` |
| โ |
| โผ |
| Screen reader immediately reads: "There are 2 errors in your submission. Link: Missing ZIP Code" |
+----------------------------------------------------------------------------------------------------+
๐ป Interactive Code Playground
Starter Code: Production Accessible One-Page Checkout (checkout.html)
Line-by-Line Code Breakdown
- Line 160 (
<form ... novalidate>): Disables the browser's default, inconsistent popup bubbles, allowing our custom, fully accessible validation script to execute. - Lines 167โ172 (
autocomplete="email",aria-describedby): Associates both helpful hint text and conditional error messages with the input usingaria-describedby="email-hint email-error". - Lines 205โ208 (
inputmode="numeric" pattern="^[0-9]{5}(-[0-9]{4})?$"): Forces mobile operating systems (iOS / Android) to display a numeric keypad while enforcing ZIP code regex patterns. - Lines 224โ226 (
inputmode="numeric" autocomplete="cc-csc"): Specifiestype="password"with numeric inputmode for CVV codes, protecting sensitive card validation codes from screen observers. - Lines 267โ304 (Accessible Focus Shift to Error Summary): When validation fails, the script populates
<div id="error-summary" role="alert" tabindex="-1">and executessummary.focus(). Non-sighted users are informed instantly of all form errors, with clickable anchor links focusing directly into invalid inputs.
Expected Browser Render Output
+---------------------------------------------------------------------------------------------------------+
| AURA LUXE CHECKOUT |
| Step 1 of 1 โ Finalize Courier Delivery & Payment |
+---------------------------------------------------------------------------------------------------------+
| [!] THERE WAS A PROBLEM WITH YOUR ORDER SUBMISSION |
| โข Email Address: Required or formatted incorrectly |
| โข Postal / ZIP Code: Required or formatted incorrectly |
+---------------------------------------------------------------------------------------------------------+
| CONTACT INFORMATION |
| Email Address * [ [email protected] ] |
| We'll send order tracking and insured courier updates here. |
+---------------------------------------------------------------------------------------------------------+
| INSURED COURIER SHIPPING ADDRESS |
| Full Legal Name * [ Laurent Mercier ] |
| Street Address * [ 742 Evergreen Terrace ] |
| City * [ Springfield ] Postal / ZIP Code * [ 97201 ] |
+---------------------------------------------------------------------------------------------------------+
| PAYMENT METHOD |
| Card Number * [ 4111 2222 3333 4444 ] |
| Expiration * [ 12/28 ] Security Code * [ โขโขโข ] |
+---------------------------------------------------------------------------------------------------------+
| [ Authorize & Pay $3,270.00 USD ] |
+---------------------------------------------------------------------------------------------------------+๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Add Real-Time Inline Input Sanitization & Live Error Clearance
Instructions:
- Attach an
inputevent listener to all required fields. - If an input previously had
aria-invalid="true"and the user edits it to a valid value, immediately removearia-invalidand hide the corresponding.field-error. - If all fields become valid, automatically hide the top
#error-summaryalert box.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Omitting
autocompleteAttributes on Checkout Inputs: Forcing users to manually type 16-digit credit cards and addresses. Mobile conversion drops by over 30% without autofill support. - Using Alert Modals for Form Errors: Calling
alert('Invalid ZIP code!'). Standard JavaScript alerts freeze the thread, destroy screen reader context, and frustrate users. Always use inline Error Summaries with focus management. - Forgetting
inputmode="numeric"on Number Fields: Usingtype="number"for credit cards and ZIP codes.type="number"causes stepper arrows to appear and strips leading zeros. Usetype="text" inputmode="numeric" pattern="[0-9]*".
๐ก Pro Tips
- Implement
aria-describedbyMulti-ID Association: Separate the helpful field instruction hint ID and the dynamic error message ID (e.g.aria-describedby="hint-id error-id"). Assistive technology reads both in logical sequence. - Apply
autocomplete="cc-csc"for CVV Fields: While historically neglected, modern browser autofill engines can securely populate CVVs from biometric-authenticated hardware tokens (Touch ID, Face ID, Windows Hello).
๐ Key Takeaways
- Implement WCAG 1.3.5 autocomplete tokens (
shipping address-line1,cc-number,cc-exp,cc-csc). - Use
inputmode="numeric"with regexpatternfor card numbers and postal codes instead oftype="number". - Add
novalidateto<form>and handle submission via the Constraint Validation API (checkValidity()). - Build an accessible Error Summary with
role="alert",tabindex="-1", and programmatic.focus()shifts. - Connect labels, hints, and error strings using
aria-describedbyandaria-invalid. - --