HTML autocomplete
Created By: chatGPT
The HTML
autocomplete
attribute allows you to control the browser's autocomplete feature on inputs. This attribute can be applied to <input>
, <select>
, and <textarea>
elements. If set to 'on', the browser will suggest previously entered values, while 'off' disables suggestions. Additionally, there are specific values like 'email', 'username', and 'address' that can provide a more enhanced user experience by giving tailored suggestions.<form>
<label for="email">Email:</label>
<input type="email" id="email" name="email" autocomplete="email">
<label for="username">Username:</label>
<input type="text" id="username" name="username" autocomplete="username">
<label for="address">Address:</label>
<input type="text" id="address" name="address" autocomplete="address-line1">
<input type="submit" value="Submit">
</form>
You can also use the 'new-password' value to suggest a new password when creating accounts. This is particularly useful for ensuring users can efficiently enter relevant information without having to remember everything manually.
Examples of input types that support autocomplete include:
- text
- password
- number
- tel
Make sure to choose the right autocomplete
value to ensure that your forms are user-friendly and secure.
<form>
<label for="new-password">New Password:</label>
<input type="password" id="new-password" name="new-password" autocomplete="new-password">
<label for="confirm-password">Confirm Password:</label>
<input type="password" id="confirm-password" name="confirm-password" autocomplete="new-password">
<input type="submit" value="Register">
</form>
While using the autocomplete feature improves usability, be cautious with sensitive information to maintain user privacy. Avoid using generic
autocomplete
values like 'off' if you want the user to benefit from the suggestions. Instead, specify what the input is for—this helps both user experience and browser functionality.<form>
<label for="cc-number">Credit Card Number:</label>
<input type="text" id="cc-number" name="cc-number" autocomplete="cc-number">
<label for="cc-exp">Expiry Date:</label>
<input type="text" id="cc-exp" name="cc-exp" autocomplete="cc-exp">
<label for="cc-cvc">CVC:</label>
<input type="text" id="cc-cvc" name="cc-cvc" autocomplete="cc-csc">
<input type="submit" value="Pay">
</form>