Why forms are harder than they look
AccessibilityAlmost every website has one.
8 min read
By Timo Wessels Published
Almost every website has one: name, email, message, a button. That looks like half an hour of work.
For what you can see, that is true. But a form is the one place on your website where a visitor does something instead of reading. Here they have to hit, type and understand why an entry is rejected. In the end, what they wrote has to reach you.
That is four places where something can go wrong. You cannot tell any of them from the finished form.
The most important points first:
- Every field needs a label that is technically tied to the field.
- Checking happens twice: in the browser for the visitor, on the server for you.
- A form is only finished when the message is in your mailbox.
The label you do not see
Every field needs a label that is technically tied to the field. A bit of text next to it is not enough.
The difference is invisible. A field with a tied label and one with loose text next to it look the same. But there is a test that takes ten seconds: click on the label text, not on the field. If the cursor jumps into the field, the tie is there. If nothing happens, it is missing.
MDN describes why that matters:
- The label is also tied to the field technically. A screen reader, a program that reads the page aloud, reads it out when the field comes up. Without it, it says “input field” and nothing else.
- If someone clicks or taps the label, the browser gives the field focus. That is a larger target. With a checkbox it means you can click the word instead of hitting the small box.
There are two ways to make the tie: the label points to the field’s id with for, or it wraps around the field. MDN advises using the reference, because not all assistive tools understand wrapping. Both at once is fine too.
The grey text in the field is not a label
The most widespread mistake comes from a design wish: the form looks tidier when the label stands in the field instead of above it.
But the text disappears as soon as someone starts typing. Whoever pauses at the third field to think what they meant to enter can no longer look. Whoever stands in front of the form again after an error message sees fields without any name.
My rule: the placeholder is never the only label. It may be there in addition, as an example of the expected format.
WCAG 3.3.2 (Level A) requires labels or instructions when content needs input. The WCAG are the international guidelines for accessible websites.
Groups need a heading
It shows most clearly with choices where only one applies. Three options stand one below the other, and each has its label. What is missing is the question they belong to. On screen it stands above as a heading. Whoever has the page read aloud hears only the answers.
For this there is the element <fieldset>. According to MDN it groups several fields and their labels, and a <legend> inside it gives the group its heading. Together they say: these fields belong together, and this is the question.
On the side, this makes long forms more readable: contact details, request and consents as three visible blocks instead of a chain of twenty fields.
The right field type and what it does not do
An input field can have different types: text, email, phone number, number, date.
The type adapts the phone keyboard. For an email field many phones show a keyboard with the @ sign, for a phone field the number pad. That saves hand movements at every field. That is how I know it from practice.
The type triggers a first check in the browser. Here: it is weaker than it looks.
- The email field checks only the pattern. MDN writes that
user@domainis valid. An address without a dot after the @ therefore passes. And it says explicitly: an address that looks valid need not exist. - The phone field does not check the format at all, because phone numbers are built too differently.
The field type is a convenience with a small checking effect, but no control.
Autofill
Browsers can fill in name, address and phone number themselves, but only if the field says what it is for. There is the attribute autocomplete for that. Without it, the browser guesses, and mostly it guesses wrong.
WCAG 1.3.5 (Level AA) requires that the purpose of fields for personal information is stored in machine-readable form. It helps several groups: whoever has trouble remembering things does not have to look them up, whoever has a motor impairment saves keystrokes, and everybody else is quicker. It is one line per field.
Checking happens in two places
This is where self-built forms are most often incomplete.
In the browser, the check is for the visitor. They should see at once that something is missing, instead of sending, waiting and getting the answer back. MDN calls it a first check and important for usability.
On the server, the check is for you. That is not convenience but the check that counts. MDN is clear: checking in the browser is not a complete security measure. Data from a form must always also be validated on the server.
My reasons for it from practice:
- Some checks only the server can do. Whether an appointment is still free, whether a customer number exists: for that you need the data, and it is not in the browser.
- The check in the browser runs on a stranger’s computer. A check the sender controls is no check.
- People make mistakes. A rule in the browser may be written wrongly and let everything through.
If your form comes from a plugin, the plugin mostly does the server check as well. If someone built the form by hand because it should look prettier, that is exactly the place to look.
What a form cannot check
Whether an email address really exists. That cannot be established while filling in. The only proof is to send a message to this address and wait for somebody to click a link in it. That is why sign-ups everywhere work by this pattern.
Whoever builds a list from a form should know: the addresses in it are unconfirmed until somebody has replied.
And then the message has to arrive
This is where almost every guide stops, and where the most goes wrong in practice.
A form is not finished when it can be submitted. It is finished when the message is in your mailbox.
In between lies a chain: your website hands the message to a sending route, the route to the recipient’s mail server, and that server decides whether to accept it, reject it or put it in spam. That depends on entries at your domain and not on the website. That is why the form says “Message sent” and still nothing arrives. It is a topic of its own with its own article.
My rule: a form counts as checked only when you have filled it in once from outside and received the mail. Not logged in, not with your own address as sender, but the way a stranger would.
What you can check yourself in ten minutes
You need no tool.
- Click on the labels. Not on the fields, on the text next to them. Does the cursor jump in?
- Go through with the Tab key. Do you reach every field? Do you see at every step where you are? Do you end on the submit button?
- Open the form on your phone. Do you get the keyboard with the @ for the email field? The digits for the phone field?
- Send it empty. Does it say which field is missing, and does it say it at the field or only as a general note at the top?
- Type something wrong. Do you understand the error message? Or is it a technical phrase that only developers read?
- Fill it in properly once, from outside, with a stranger’s address. Does the mail arrive? How fast? In the inbox or in spam?
The unspectacular core
Nothing about a form is difficult. Every point here is a line of markup or a setting in the plugin.
They still fail regularly, because a form counts as finished once it looks pretty and can be submitted. That is the state most forms are in, and in it they are more tiring for half the visitors than they need to be.
Sources
- MDN, The Label element — the label is also tied to the field technically; a click on the label sets the focus; reference via
foror wrapping, the reference is recommended: developer.mozilla.org(external site: developer.mozilla.org) - MDN, The Field Set element —
<fieldset>groups fields,<legend>gives the heading: developer.mozilla.org(external site: developer.mozilla.org) - MDN,
<input type="email">— the pattern is checked,user@domainis valid, the address need not exist: developer.mozilla.org(external site: developer.mozilla.org) - MDN,
<input type="tel">— no automatic format check: developer.mozilla.org(external site: developer.mozilla.org) - MDN, Client-side form validation — checking in the browser is a first check, not a complete security measure; checking on the server stays necessary: developer.mozilla.org(external site: developer.mozilla.org)
- MDN, HTML attribute: autocomplete — the browser fills in fields from the statement: developer.mozilla.org(external site: developer.mozilla.org)
- W3C, Understanding SC 3.3.2: Labels or Instructions — labels or instructions for inputs, Level A: w3.org(external site: w3.org)
- W3C, Understanding SC 1.3.5: Identify Input Purpose — the purpose of fields for personal information is machine-readable, Level AA: w3.org(external site: w3.org)
- Own testing practice — the placeholder is never the only label, the three reasons for the server check, the phone keyboard, the order of the self-check, the rule that a form counts as checked only after a mail from outside.