Visitors rarely abandon a lead form because they dislike typing. They abandon it because their browser guessed wrong: it drops a work email into the phone field, or fills a street address into an organization input. Form autocomplete attribute best practices fix most of that with one short attribute per field, but only if you choose the right token and test it after any widget modifies the markup.
The autocomplete attribute gives browsers a declared hint about what a field expects, so autofill can do a useful job instead of guessing from the name and label text. With odd or missing tokens, it guesses, and guesses drift toward the wrong autocomplete.
What the autocomplete attribute actually controls
Browsers combine two inputs when deciding what to fill. First, heuristics: the name, id, label wording, type and nearby text. Second, the declared autocomplete token. The token wins when it is valid and specific. When it is missing or unrecognised, the heuristic decides, which is why a field called company sometimes receives a person's name.
Declared tokens are the dependable layer. Treat them as required, not optional, on every input in a lead form you maintain.
A field-by-field token map for lead forms
Use these tokens verbatim. They are the common ones a contact or quote form needs.
| Field | Input type | autocomplete token |
|---|---|---|
| First name | text |
given-name |
| Last name | text |
family-name |
| Full name (single field) | text |
name |
email |
email |
|
| Phone | tel |
tel |
| Company / organization | text |
organization |
| Street address | text |
street-address |
| Town or city | text |
address-level2 |
| Postcode | text |
postal-code |
| Country | select |
country-name |
A few of these deserve a note. Use name only when one field holds the whole name; if you split first and last, use given-name and family-name so each field gets the right half. Use tel for a number where any phone format is acceptable.
Some fields should not carry a token. A marketing form's "How did you hear about us?" select, a free-text "Tell us about your project" textarea, and a budget range have no sensible browser autofill, and adding a token invites wrong data. Leave them without autocomplete and make the label do the work. If your labels need work, see HTML form labels for clear lead forms.
Why not autocomplete=off, and when off is still right
Setting autocomplete="off" on every field is the most common mistake. Browsers often override it for fields they believe hold contact details, so the attribute adds noise without changing behaviour. On fields the heuristic recognises, some browsers fill anyway.
There are still places where off is correct:
- Search fields inside the page (as opposed to address autofill).
- One-time codes from a text message or email, where a stored value is always stale.
- Honeypot fields, which must never receive a real value from autofill. A honeypot is only useful if a human is unlikely to fill it; autofill could populate it by accident, so keep it empty and excluded. Our guide to detected form widget honeypot spam protection walks through the timing and hidden-field side.
If you are deciding field by field rather than blanket-disabling, the wider trade-offs are covered in autocomplete off contact form fields: when it helps or hurts.
One more specific trap: email. The token must be exactly email, and the input type must also be email; mismatches are a common reason autofill skips the field. For the deeper fix, see email autocomplete attribute HTML form: fix email autofill.
Pair autocomplete with type and inputmode
The token tells the browser what the field means. type and inputmode tell the browser and the mobile keyboard how to behave. Set all three and the form works on desktop autofill and on a phone keyboard.
<label for="lead-name">First name</label>
<input id="lead-name" name="first_name" type="text" autocomplete="given-name" required>
<label for="lead-email">Work email</label>
<input id="lead-email" name="email" type="email" autocomplete="email" inputmode="email" required>
<label for="lead-phone">Phone</label>
<input id="lead-phone" name="phone" type="tel" autocomplete="tel" inputmode="tel">
On mobile, type="email" and inputmode="email" usually produce an @ key; type="tel" produces a numeric keyboard. Keep the token matching the type.
Validation order: native constraints and filled values
Autofill and validation interact. A browser may fill a value programmatically, and some constraints behave differently when that happens. MDN's guidance on form validation notes that length constraints are not reported when a value is set programmatically; they are only reported for user-provided input. So do not rely on minlength alone to catch a bad autofilled value. Check on submit and on the server.
A sensible order for a lead form:
- Declare
requiredon the fields you actually need, and usetype(email,tel) so the browser can check format. - Add
minlength/maxlength/patternwhere format matters, but treat them as hints, not guarantees. - On submit, run any script checks and let the browser focus the first invalid field with a visible message.
- Always validate on the server when the value arrives. MDN's sending and retrieving form data is explicit that client-side checks are not exhaustive security, and that form data must be handled on the server.
If you want to customize the browser's own messages, read native HTML form validation messages customizing. It shows how to set custom messages without replacing native behaviour.
Keep passwords and card data out of detected forms
The detected form widget connects an existing HTML form to WidgetJar so submissions are captured; it is not a payment or password tool. Do not place password inputs or card number fields on a marketing form at all. If a page includes them for any reason, keep them out of the detected form scope and keep their autocomplete tokens to current-password, new-password or the card tokens. These are the fields where autofill is expected and useful, and where a stray token is risky. Our guide to adding a consent checkbox to an existing form covers keeping sensitive fields out while still recording consent.
A post-embed test script
Run this after the detected form widget is installed, because the script may change markup, add fields or wrap the form.
- Open the page in Chrome, Safari and Firefox on desktop. For each field, check the browser's autofill suggestion list shows the expected entry (name, email, phone), not an unrelated one.
- Fill the form with autofill only, submit, and confirm the submission is captured and that a required consent checkbox was not skipped.
- On one phone (iOS or Android), trigger autofill on the email and phone fields and confirm the keyboard and suggestions match.
- Submit an empty form and confirm native validation blocks it and focuses the first invalid field.
- Check the browser dev tools network panel to confirm the data reaches the endpoint you expect once the widget is active.
- Confirm the honeypot field was not filled by autofill, and that a stray value in it does not block a real submission.
If any step fails, check the token spelling first, then that type and autocomplete agree, then that the widget has not duplicated the input.
Put the map to work
Write down the token for every input in your lead form, mark the ones that should stay empty, and re-test on all three browsers after the first real install. If you want the widget to capture submissions from a form you already run, connect your existing HTML form with the detected form widget and verify each field end to end before launch.