HTML5 Intermediate Accessible Forms · 8 min read

Autocomplete Tokens on Inputs

Lesson 26 of 36 in the HTML5 learning path.

How do I help browsers fill a checkout form correctly?

Browsers fill a checkout form by reading autocomplete tokens, not by guessing from the words in a label. The token list can start with shipping or billing, then a field name such as given-name, address-line1, or postal-code. Card fields use their own names: cc-name, cc-number, cc-exp, and cc-csc.

The name attribute is the key your server receives. The autocomplete attribute is the hint the browser uses to pick a saved value. Matching input types help too: email for an email token, tel for a telephone token, and text rather than number for a card so spaces and leading zeros survive.

Syntax & Parameters

Syntax
<input name="given-name" autocomplete="shipping given-name" required>

Example

Interactive preview available
form.html
<form action="/checkout" method="post">
  <h1>Ship this kit</h1>
  <label for="given-name">Given name</label>
  <input id="given-name" name="given-name" type="text" autocomplete="shipping given-name" required>
  <label for="family-name">Family name</label>
  <input id="family-name" name="family-name" type="text" autocomplete="shipping family-name" required>
  <label for="email">Email</label>
  <input id="email" name="email" type="email" autocomplete="shipping email" required>
  <label for="phone">Phone</label>
  <input id="phone" name="tel" type="tel" autocomplete="shipping tel" required>
  <label for="address-line1">Street address</label>
  <input id="address-line1" name="address-line1" type="text" autocomplete="shipping address-line1" required>
  <label for="city">City</label>
  <input id="city" name="address-level2" type="text" autocomplete="shipping address-level2" required>
  <label for="region">State or region</label>
  <input id="region" name="address-level1" type="text" autocomplete="shipping address-level1" required>
  <label for="postal-code">Postal code</label>
  <input id="postal-code" name="postal-code" type="text" autocomplete="shipping postal-code" required>
  <label for="country-name">Country</label>
  <input id="country-name" name="country-name" type="text" autocomplete="shipping country-name" required>
  <label for="cc-name">Name on card</label>
  <input id="cc-name" name="cc-name" type="text" autocomplete="cc-name" required>
  <label for="cc-number">Card number</label>
  <input id="cc-number" name="cc-number" type="text" inputmode="numeric" autocomplete="cc-number" required>
  <label for="cc-exp">Expiration</label>
  <input id="cc-exp" name="cc-exp" type="text" autocomplete="cc-exp" required>
  <label for="cc-csc">Security code</label>
  <input id="cc-csc" name="cc-csc" type="text" inputmode="numeric" autocomplete="cc-csc" required>
  <button type="submit">Place order</button>
</form>

Expected Output

A checkout form whose recipient fields use shipping tokens for name, email, phone, street, city, region, postal code, and country, followed by cc-name, cc-number, cc-exp, and cc-csc on the payment fields.

Line-by-Line Walkthrough

  1. The form posts the checkout. Each control has a visible label tied with for and id.
  2. shipping given-name and shipping family-name mark the recipient, which can differ from the person paying.
  3. type="email" and type="tel" match the email and tel tokens so the browser offers the right saved contact value.
  4. address-line1, address-level2, address-level1, postal-code, and country-name are the tokens for street, city, region, postal code, and country.
  5. The shipping hint in front of those tokens keeps this group distinct from a billing group on the same page.
  6. cc-name, cc-number, cc-exp, and cc-csc are payment tokens. They do not take the shipping hint.
  7. The card field stays type="text" with inputmode="numeric" so a number input cannot reject spaces or leading zeros.
  8. required asks the browser for a value before submit. It does not check that the card number is real.
  9. The server still validates every field. Autocomplete only helps the browser choose what to insert.

Common Pitfalls & Security

Autocomplete is a hint to the browser. It is not validation, and it is not a reason to trust the posted card data. Check the payment on the server and do not store the security code after authorization.

  • autocomplete="firstname" is not a token. The spec name is given-name. Invented words fall back to unreliable guesses from name and id.
  • autocomplete="off" does not reliably stop password managers on login fields. Use current-password or new-password for those controls.
  • Two address blocks that both say given-name, with no shipping or billing hint and no section-* token, get each other's saved values.
  • type="number" on a card field drops leading zeros and rejects the spaces people type. Use type="text" and inputmode="numeric".
  • country expects a code, while country-name expects the country in words. Swapping them fills the wrong shape of value.
  • Collecting cc-csc is sometimes required to charge the card. Persist it and you have stored data you are not allowed to keep. Send it with the charge and drop it.

Best Practices & Modern Standards

Put a spec token on every checkout control, with shipping or billing in front of address and contact fields when both appear. Use section-ship or section-bill when one page has two shipping addresses. Pair the token with a real label, an appropriate type, and autocomplete on the input itself.

Serve the form over HTTPS so browsers will offer payment autofill. Ignore nothing on the server: validate the address, charge through a payment provider, and treat the posted security code as transient. A correct token does not make a fraudulent card legitimate.

Real-World Use

The kit checkout labels the recipient as shipping and the card fields with cc-name, cc-number, cc-exp, and cc-csc. A returning student gets the saved campus address in the street and city fields instead of the billing address. The charge request uses the card tokens the browser inserted, and the application drops the security code after the provider responds.

Frequently Asked Questions

What is the shipping token for?

It marks the following field as the shipping address or shipping contact, so the browser does not insert the billing value into that box.

Why not use type number for a card?

A number input rejects spaces and can drop leading zeros. Card numbers need type="text", with inputmode="numeric" if you want a digit keypad.

Does autocomplete off stop password managers?

Often no. Managers override off on username and password fields. Use current-password for a sign-in and new-password when the person is choosing a password.

Does the browser check the card number?

No. The token only helps fill the field. Your server, or the payment provider, must check the number before charging it.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…