Problem Statement
What does autocomplete="off" do?
Explanation
The autocomplete equals off disables browser auto-fill suggestions for that input field. Browsers remember values users previously entered and offer to auto-fill them. Setting autocomplete to off prevents this behavior. This is useful for sensitive fields, one-time codes, new passwords, or fields where suggestions would not be helpful. The autocomplete attribute can also have specific values like name, email, tel, or cc-number to provide hints about what type of data the field expects. These hints help browsers provide better auto-fill suggestions. For example, autocomplete equals email tells the browser this field expects an email address. Modern browsers use these hints to auto-fill forms more accurately. You can set autocomplete on individual inputs or on the form element to apply to all fields. Use autocomplete equals off for sensitive data but allow it for convenience fields like addresses and emails.
Code Solution
SolutionRead Only
<!-- Disable autocomplete for sensitive field -->
<form>
<label for="credit-card">Credit Card:</label>
<input type="text"
id="credit-card"
name="cc"
autocomplete="off"
required>
<label for="cvv">CVV:</label>
<input type="text"
id="cvv"
name="cvv"
autocomplete="off"
maxlength="3"
required>
</form>
<!-- Enable autocomplete with hints -->
<form autocomplete="on">
<label for="name">Full Name:</label>
<input type="text"
id="name"
name="name"
autocomplete="name"
required>
<label for="email">Email:</label>
<input type="email"
id="email"
name="email"
autocomplete="email"
required>
<label for="tel">Phone:</label>
<input type="tel"
id="tel"
name="phone"
autocomplete="tel"
required>
</form>
<!-- New password (no suggestions) -->
<form>
<label for="new-pass">New Password:</label>
<input type="password"
id="new-pass"
name="password"
autocomplete="new-password"
required>
</form>