HTML autocomplete Attribute

Beginner
7 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The autocomplete attribute tells the browser whether it may autofill a control and, with tokens, what kind of data to suggest. Use it on text or numeric <input> controls, <textarea>, <select>, and on a <form> as a default for its fields.

The value is either on, off, or a space-separated list of autofill tokens (for example given-name or shipping postal-code). Valid tokens also help meet WCAG 2.2 Success Criterion 1.3.5 (Identify Input Purpose).

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers. Autofill UI still differs by browser and saved user data.

off is not a password lock.

Most browsers still offer password-manager fill on login fields. Prefer semantic tokens like username and current-password instead of fighting autofill.

HTML Syntax

syntax.html
<element autocomplete=" on | off | token-list">

If a field omits autocomplete, the browser uses the value from its owning <form> (via nesting or the form attribute).

Attribute Values

Start with these common values. Tokens can be combined with optional shipping / billing or a section-* group name.

ValueDescriptionTry it
offDo not autofill (browsers may still ignore this on login fields)Try it
onAllow autofill without naming a specific data typeTry it
given-name / family-nameFirst and last name partsTry it
email / tel / usernameContact or account identifiersTry it
current-password / new-passwordLogin password vs create/change passwordTry it
street-address / postal-codeAddress pieces; often prefixed with shipping or billingTry it
one-time-codeOTP / verification code from SMS, email, or an authenticatorTry it

Many more tokens exist (payment cc-*, birthday bday, organization, and so on). Prefer standard tokens over made-up strings.

Live Preview

Change the autocomplete token, then focus the field. Suggestions appear only if your browser has matching saved data.

A real form field. Apply a token, then click the input to see if your browser offers autofill.

Demo form

autocomplete="given-name"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Name and Email Tokens

Label each field with a clear autofill purpose.

HTML
<form action="/subscribe" method="post">
  <label for="firstName">First name:</label>
  <input type="text" id="firstName" name="firstName" autocomplete="given-name">

  <label for="lastName">Last name:</label>
  <input type="text" id="lastName" name="lastName" autocomplete="family-name">

  <label for="email">Email:</label>
  <input type="email" id="email" name="email" autocomplete="email">

  <button type="submit">Subscribe</button>
</form>
Try It Yourself

How It Works

  1. Pick a token per field. given-name, family-name, and email map to stored contact data.
  2. Keep name and id. Browsers often need them (plus a form and submit) to offer autofill.
  3. Match the input type. type="email" pairs naturally with autocomplete="email".
  4. Accessibility win. Purpose tokens help assistive tech and WCAG 1.3.5.

Example 2 — Login with Password Tokens

Help password managers fill the right fields — and use new-password when creating an account.

HTML
<form action="/login" method="post">
  <label for="user">Username:</label>
  <input type="text" id="user" name="username" autocomplete="username">

  <label for="pass">Password:</label>
  <input type="password" id="pass" name="password" autocomplete="current-password">

  <button type="submit">Sign in</button>
</form>
Try It Yourself

How It Works

  1. username marks the account identifier for password managers.
  2. current-password means “existing password” for sign-in.
  3. Use new-password on create-account or change-password fields so managers do not paste the old password by mistake.
  4. Avoid fake tokens to “block” autofill — that hurts accessibility and often fails anyway.

Example 3 — Shipping Address Group

Combine a grouping token with detail tokens so shipping and billing stay distinct.

HTML
<form action="/checkout" method="post">
  <label for="street">Street address:</label>
  <textarea id="street" name="street" autocomplete="shipping street-address"></textarea>

  <label for="city">City:</label>
  <input type="text" id="city" name="city" autocomplete="shipping address-level2">

  <label for="zip">Postal code:</label>
  <input type="text" id="zip" name="zip" autocomplete="shipping postal-code">

  <button type="submit">Continue</button>
</form>
Try It Yourself

How It Works

  1. shipping groups these fields as the delivery address (use billing for payment address).
  2. Detail tokens name the piece: street, city (address-level2), postal code.
  3. Space-separated list keeps the full meaning unique vs a billing twin of the same detail token.
  4. Need two shipping addresses? Prefix with section-home / section-work so groups stay unique.

Edge Cases & Pitfalls

Most issues come from blocking autofill or using non-standard values.

login

off often fails on login

Password managers may still fill username/password. Use proper tokens; reserve off for cases like CAPTCHA where autofill truly hurts.

a11y

Fake tokens break purpose

Made-up strings stop helpful autofill and fail WCAG 1.3.5. Prefer real tokens or a justified off.

setup

Form + name/id + submit

Many user agents expect a name and/or id, a form ancestor, and a submit control before offering suggestions.

hidden

Hidden inputs cannot use on/off

On type="hidden", autocomplete must be a token list — not the keywords on or off.

firefox

Firefox persists some form state

Unlike other browsers, Firefox may restore disabled/checked state across loads unless you set autocomplete="off" (even on types where autofill otherwise seems irrelevant).

Browser Support

autocomplete is an HTML attribute for form controls in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

autocomplete

Widely supported across modern desktop and mobile browsers. Which suggestions appear depends on saved profiles, password managers, and each browser’s autofill UI.

97% Global support (approx.)
Google Chrome Modern · Full
Full support
Mozilla Firefox Modern · Full
Full support
Apple Safari Modern · Full
Full support
Microsoft Edge 79+
Full support
Opera Modern · Full
Full support
Samsung Internet Modern · Full
Full support
Internet Explorer Partial / older behavior
Partial
autocomplete Widely supported

Bottom line: Safe to use everywhere for UX and accessibility. Expect autofill UI and password-manager behavior to vary — test on your target browsers.

Key Takeaways

  • Role: allow or guide autofill with on, off, or purpose tokens.
  • Prefer tokens: email, given-name, current-password, and friends beat bare on.
  • Groups: shipping / billing and section-* keep address sets unique.
  • Don’t overuse off: it harms accessibility and often fails on login forms.

One line: name the field’s purpose with standard tokens — let the browser help users fill it.

Frequently Asked Questions

It tells the browser whether it may autofill a field and, with tokens like email or given-name, what kind of data to suggest.
It works on text or numeric input types, textarea, select, and form. If a field omits it, the owning form’s autocomplete value is used.
Usually not on login fields. Most browsers still offer to save or fill usernames and passwords. Prefer username and current-password tokens for login forms.
Tokens identify the field’s purpose (WCAG 1.3.5). That helps browsers, password managers, and assistive tech offer the right stored data.
They group address or contact tokens. Example: shipping postal-code vs billing postal-code so the browser can fill two different addresses.
Browsers often need a name or id, a form ancestor, and a submit control. Suggestions come from saved user data and may vary by browser.

Next: autofocus

Automatically focus a form control when the page loads.

autofocus tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful