HTML Autocomplete: Help Browsers Understand Form Fields

HTML form autofill settings and input completion tokens for names and delivery addresses.

Add the autocomplete attribute to a form or field to tell the browser whether it may offer saved values and, more precisely, what a field represents. Autocompletion in HTML can make a checkout or sign-in form easier to complete, especially on a small screen.

A meaningful token such as email or postal-code gives the browser more information than a generic on/off setting. HTML form autofill remains a hint: the user’s settings, saved data, browser, and password manager all influence what actually happens.

Autocomplete HTML: Start with a working form

Save this example as an HTML file and open it in a browser. It does not send data to a server; submitting displays a message so you can explore the fields without building a backend.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Delivery form</title>
</head>
<body>
  <form id="delivery" autocomplete="on">
    <p><label for="name">Full name</label>
      <input id="name" name="name" autocomplete="name" required></p>
    <p><label for="email">Email</label>
      <input id="email" name="email" type="email"
             autocomplete="email" required></p>
    <p><label for="street">Street address</label>
      <input id="street" name="street" autocomplete="shipping street-address"></p>
    <p><label for="zip">ZIP code</label>
      <input id="zip" name="zip" autocomplete="shipping postal-code"></p>
    <p><label for="reference">One-time delivery reference</label>
      <input id="reference" name="reference" autocomplete="off"></p>
    <p><label for="note">Delivery note</label>
      <input id="note" name="note"></p>
    <button type="submit">Check form</button>
  </form>
  <p id="result" role="status"></p>
  <script>
    document.querySelector('#delivery').addEventListener('submit', event => {
      event.preventDefault();
      document.querySelector('#result').textContent = 'Form checked locally.';
    });
  </script>
</body>
</html>

The form sets a general default of on. The note field has no attribute of its own, so it takes the form owner’s on/off setting. The reference field explicitly requests off, while the other fields provide specific tokens. Those field-level values override the form’s default. The MDN autocomplete reference describes the available values and their order.

HTML autocomplete does not create saved data or guarantee a suggestion. Use HTML autocomplete to describe the expected information rather than to simulate a filled field. If your browser has no suitable profile, there may be nothing to fill. A browser may also use other clues, including the control’s name, type, and associated form. Give fields stable name and id values and connect visible labels to their controls, as the example does.

Understand on, off, and defaults

On a form, autocomplete="on" allows the browser to offer automatic completion by default; autocomplete="off" asks it not to do so for controls without their own setting. If the form does not specify the attribute, its default is generally on. A control can set its own on, off, or appropriate token list, replacing that inherited setting.

For an input in HTML, autocomplete can therefore be configured more precisely than its parent form. An individual input can carry its own autofill hint even when adjacent inputs inherit the form setting. For example, a form may use off as a default while an email field specifies autocomplete="email". Conversely, a mostly reusable address form may request off for a one-time reference. Choose such exceptions for a reason, not as a blanket attempt to control every browser behavior.

An off request is not a security boundary. Browsers and password managers may still offer to save or fill login credentials, including when a form asks them not to. Do not rely on it to protect sensitive information or replace server-side validation and secure handling. The browser’s suggestions are decisions made in the context of the user’s preferences and stored data.

Give fields meaningful tokens

The HTML input autocomplete attribute can identify the expected content. Common examples include name, given-name, family-name, email, tel, street-address, and postal-code. Use the token that matches the information requested: a full-name field should not claim to be a family-name field. For login forms, username and current-password identify existing credentials; new-password identifies a password being created or changed.

For autocomplete, HTML also supports ordered token lists that distinguish related groups. The example uses shipping street-address and shipping postal-code. A separate billing address can use billing street-address and billing postal-code, helping a browser distinguish the two. If a form has multiple distinct shipping addresses, a leading section-* token such as section-first can identify a group; use the same section token on fields belonging to that group.

HTML5 autocomplete is often used as a name for these form capabilities, but the feature belongs to the HTML standard. In an HTML5 form, autocomplete tokens can identify each field more precisely. Token spelling and order matter: write space-separated values in the documented order, rather than inventing labels or combining on with a detail token. Hidden inputs have special rules: if the attribute is present, they use a token list rather than on or off.

The autocomplete setting on an HTML input also does a different job from its type. A browser can use the input completion hint to select a relevant saved value. type="email" identifies and validates the general shape of an email field in supporting browsers, while autocomplete="email" describes the value for autofill. Neither guarantees that the address exists or belongs to the person submitting it. Keep normal validation and error feedback in place.

Test the form as a person would use it

Check the markup first: each field should have a visible label, a meaningful name, and a token matching the data requested. Try the form with a browser profile containing test data and again with no saved profile. Compare the inherited note field with the explicitly disabled reference field, but record the browser’s actual behavior rather than assuming it follows every hint.

Test the HTML form’s autocomplete behavior in the browsers and password managers your audience uses. Include keyboard navigation, mobile layouts, shipping and billing groups, and login or password-change flows where applicable. With HTML5 form autofill, a suggestion may appear only after focus, typing, or a suitable saved profile; absence of a suggestion alone does not prove the markup is wrong.

Finally, submit representative values and check that labels, validation messages, and server-side handling still work whether a field was filled manually or automatically. A well-described form helps the browser offer assistance while leaving the person in control of the information submitted.