HTML autocomplete Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Input

Introduction

The autocomplete attribute is a handy feature in HTML that allows developers to control whether a browser should automatically complete user input in a form. This attribute is applied to form elements and can be particularly useful for enhancing user experience and streamlining data entry.

What You’ll Learn

01

on / off

Enable or disable.

02

Token Values

email, name, tel.

03

Passwords

current / new.

04

Form Scope

input, form, textarea.

05

JavaScript

Set dynamically.

06

Security

When to use off.

Purpose of autocomplete

The primary purpose of the autocomplete attribute is to specify whether a browser should provide autocomplete suggestions for a particular input field. By default, most browsers have autocomplete enabled, which means they try to predict and fill in values based on the user’s previous inputs. However, there are situations where you might want to control or disable this behavior.

💡
Prefer Semantic Tokens

Instead of generic on, use tokens like email or name so browsers and password managers fill the correct data.

📝 Syntax

Add autocomplete to a form control with on, off, or a semantic token:

autocomplete.html
<input type="email" autocomplete="email">

Syntax Rules

  • Valid on input, select, textarea, and form.
  • Use off to disable autofill for a specific field.
  • Use semantic tokens for better autofill accuracy.
  • Setting autocomplete on <form> applies to all fields unless overridden.

💎 Values

The autocomplete attribute accepts various values to define different behaviors. The two main values are:

  • on — Allows the browser to provide autocomplete suggestions for the input field (default in many cases).
  • off — Disables autocomplete for the input field. Use when you want to prevent the browser from suggesting or remembering previous input.

Common semantic tokens include:

  • name, email, tel, street-address — Contact and address fields.
  • current-password — Login password field.
  • new-password — Registration or password-change field.
  • one-time-code — SMS or email verification codes.
autocomplete-values.html
<input autocomplete="off">
<input autocomplete="email">
<input type="password" autocomplete="current-password">
<input type="password" autocomplete="new-password">

⚡ Quick Reference

Field TypeSuggested ValueNotes
Login passwordcurrent-passwordPassword manager autofill
New passwordnew-passwordSign-up or reset forms
EmailemailBetter than generic on
OTP / captchaoff or one-time-codeDo not reuse saved values
Credit card (sensitive)cc-number or offFollow PCI guidelines
Applicable elementsinput, form, textareaForm controls

Applicable Elements

ElementSupported?Notes
<input>YesMost common use
<textarea>YesMulti-line text
<select>YesLimited autofill effect
<form>YesSets default for child fields

Examples Gallery

on/off form example, dynamic new-password, and semantic token values.

👀 Live Preview

Login form with controlled autofill:

Example

Here’s a simple example of how to use the autocomplete attribute in an HTML form:

autocomplete.html
<form>
  <label for="username">Username:</label>
  <input type="text" id="username" name="username" autocomplete="off">

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

  <input type="submit" value="Submit">
</form>
Try It Yourself

How It Works

In this example, the autocomplete attribute is set to off for the username input field, disabling autofill suggestions for that field. The password field uses current-password so password managers can offer the saved login credential.

Dynamic Values with JavaScript

You can also dynamically set the autocomplete attribute using JavaScript. This can be useful when you want to customize autocomplete behavior based on certain conditions or user interactions. Here’s a brief example:

dynamic-autocomplete.html
<input type="password" id="dynamicField">

<script>
  document.getElementById("dynamicField").autocomplete = "new-password";
</script>
Try It Yourself

How It Works

In this script, the autocomplete attribute is set to new-password for an input field with the id dynamicField. This prompts password managers to suggest a strong new password during registration.

Example — Semantic Token Values

Use specific tokens so browsers know exactly what data to autofill:

token-autocomplete.html
<input type="text" autocomplete="name">
<input type="email" autocomplete="email">
<input type="tel" autocomplete="tel">
Try It Yourself

How It Works

Semantic tokens describe the field’s purpose. Browsers map them to saved autofill profiles for faster, more accurate form completion.

♿ Accessibility

  • Improves usability — Autofill reduces typing effort for users with motor disabilities.
  • Pair with labels — Autocomplete does not replace accessible <label> elements.
  • Use correct tokens — Helps assistive tech and password managers identify field purpose.
  • Do not disable unnecessarily — Turning off autofill on standard login fields can frustrate users.

🧠 How autocomplete Works

1

Author sets autocomplete

Choose on, off, or a semantic token per field.

Markup
2

User focuses the field

Browser reads the autocomplete hint.

Focus
3

Browser offers saved values

Autofill dropdown or password manager fills the field.

Autofill
=

Faster, easier form entry

Users complete forms with less typing and fewer errors.

Browser Support

The autocomplete attribute is supported in all modern browsers. Behavior may vary slightly—some browsers ignore off on login fields for usability.

HTML5 · Fully supported

Universal autofill control

All major browsers honor autocomplete on form controls.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
autocomplete attribute 99% supported

Bottom line: Use semantic tokens and test autofill in Chrome, Firefox, and Safari.

💡 Best Practices

✅ Do

  • Use semantic tokens (email, name, tel)
  • Use current-password and new-password for passwords
  • Set autocomplete="off" on one-time codes and captchas
  • Test forms with browser autofill and password managers
  • Consider user experience when disabling autofill

❌ Don’t

  • Disable autofill on standard login fields without good reason
  • Rely on off alone for security (browsers may override)
  • Use generic on when a specific token exists
  • Forget name attributes (autofill uses them too)
  • Assume all browsers treat off identically

Conclusion

The autocomplete attribute is a valuable tool for controlling the autocomplete behavior of form elements in HTML. By understanding and using this attribute appropriately, you can enhance the usability and security of your web forms.

Choose semantic tokens over generic values, use password-specific tokens for credential fields, and reserve off for fields that should never reuse saved data.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about autocomplete

Bookmark these before building your next form.

5
Core concepts
🏷 02

Tokens

email, name, tel.

Semantic
🔒 03

Passwords

current / new.

Security
⚙️ 04

JavaScript

.autocomplete

Dynamic
👤 05

UX Win

Faster forms.

Usability

❓ Frequently Asked Questions

It controls whether the browser suggests or autofills values in a form field based on previously entered data.
input, textarea, select, and form elements.
Usually no. Use current-password for login and new-password for sign-up so password managers work correctly.
Semantic tokens like email, name, or street-address give browsers clearer autofill hints.
Yes. Assign element.autocomplete = "new-password" or use setAttribute at runtime.
Not always. Some browsers may still offer autofill on login fields for user convenience. Test in target browsers.

Build smarter autofill forms

Practice the autocomplete attribute with login, password, and contact field examples in the Try It editor.

Try form example →

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.

5 people found this page helpful