Most form errors I see on store sites are a red border and a word in small red text that appears somewhere near the field. Sighted mouse users usually figure it out. Everyone else gets a form that just refuses to submit and doesn't say why.
Good error handling isn't complicated. It's mostly HTML that's been around for years, plus a couple of decisions about timing. Here's the checklist I use when I review a form, whether it's a checkout, a contact form, or the "pick a size" step on a product page.
Tie the message to the field
The error text has to be connected to its input, not just placed near it visually.
<label for="phone">Phone number</label> <input id="phone" name="phone" type="tel" autocomplete="tel" aria-invalid="true" aria-describedby="phone-hint phone-error" > <p id="phone-hint">We'll only call if there's a problem with delivery.</p> <p id="phone-error" class="field-error">Enter a phone number with at least 9 digits.</p> -
aria-describedbymakes the screen reader read the error when the field gets focus. You can list several ids, so the hint and the error can both be attached. -
aria-invalid="true"goes on only when the field actually has an error. Don't ship it as"false"hard-coded in a template and forget to flip it, and don't set it to"true"before the user has typed anything. - Keep the error element in the DOM and empty it, or add and remove it together with the
aria-describedbyreference. A reference to an id that doesn't exist is harmless but messy; an error that exists but isn't referenced is invisible to assistive tech.
Say what to do, not what went wrong
"Invalid input" is the classic. Compare:
- "Invalid phone" → "Enter a phone number with at least 9 digits."
- "Required" → "Choose a size before adding to cart."
- "Invalid date" → "Enter the date as DD/MM/YYYY."
The second version is a little longer and a lot more useful. If there's a format, show it in the hint before the error happens, not only after.
Don't rely on red
A red border is fine as an extra signal. On its own it fails for people who don't see red well, and it fails in forced-colors / high-contrast mode, where your border color may be replaced entirely. Add an icon or the word "Error:" in the message, and make sure the text itself has enough contrast against the background. Pale red on white often doesn't.
When to validate
This is where most of the debate happens. What I've ended up with:
- On submit: always. This is the one moment the user clearly asked "is this okay?"
- On blur (leaving the field): fine for fields with a clear format, like email or phone, but only after the user has typed something. Tabbing through an empty form shouldn't light it up in red.
- While typing: only to clear an error once it's fixed. Showing "too short" after the first character is just noise.
On submit, give a summary and move focus
If the form has more than two or three fields, a summary at the top saves people from hunting.
<div id="error-summary" tabindex="-1" role="alert"> <h2>There are 2 problems with your details</h2> <ul> <li><a href="#phone">Enter a phone number with at least 9 digits</a></li> <li><a href="#city">Enter your city</a></li> </ul> </div> form.addEventListener('submit', (e) => { const errors = validate(form); if (errors.length === 0) return; e.preventDefault(); renderSummary(errors); // fills the list above markFields(errors); // sets aria-invalid + message per field document.getElementById('error-summary').focus(); }); Each link jumps straight to the field. For a short form, skip the summary and move focus to the first invalid field instead. Either way, don't leave focus on the submit button with nothing announced.
Native validation: use it, or turn it off on purpose
The browser's built-in required / type="email" bubbles are better than nothing, but they look different in every browser, disappear after a few seconds, and can't be styled. If you build your own messages, add novalidate to the <form> so you don't get both at once. Keep required and the input types anyway; they still help with keyboards on mobile and with autofill.
Don't wipe the form
If submit fails on the server (stock changed, session expired, payment declined), keep what the person typed. Re-rendering an empty checkout after an error is the fastest way to lose someone. Password and card fields are the reasonable exceptions.
The non-form forms
Product pages have hidden forms too. The size or color picker on clothing is the common one. On things like work shirts, where you must pick a size before adding to cart, the same rules apply: the size group needs a label (a <fieldset> with a <legend> works well), and "Add to cart" without a size should produce a real message tied to that group and move focus to it, not just shake the button.
Five-minute test
- Submit the form empty with a screen reader on. Do you hear what's wrong and where?
- Fix one field. Does its error clear?
- Tab through without typing anything. Does anything turn red? (It shouldn't.)
- Turn on forced colors (Windows high contrast or the DevTools emulation). Can you still see which field is wrong?
- Trigger a server-side error. Is your input still there?
None of this needs a form library, although a good one will handle most of it for you. What's the error message pattern you've seen that annoyed you most? Mine is the password field that only tells you the rules after you've broken three of them.


