Toggling Auto-complete ON and OFF in HTML Form

We all must have experience this while filling an online form; our respective web browser auto-completing text when entering it in an HTML input field.
On one of my pet web project, i disabled auto-complete from working when users is registering. just thought i should share, who knows, maybe it could be of help to someone.

Disabling auto-complete is made possible simply by declaring the autocomplete attribute. the syntax is <input autocomplete=”on|off”>.
Let’s see some example to understand how it works.

Disabling auto-complete in all form fields

This can easily be done by declaring the value of autocomplete to off in the HTML <form> tag.


<form action="" autocomplete="off">
  First name:<input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  E-mail: <input type="email" name="email" ><br>
  <input type="submit">
</form>
Disabling auto-complete in specific input field(s)

In this example, auto complete is off only in the Email input field


<form action="" >
  First name:<input type="text" name="fname"><br>
  Last name: <input type="text" name="lname" ><br>
  E-mail: <input type="email" name="email" autocomplete="off"><br>
  <input type="submit">
</form>
Auto-complete ON in specific input field(s)

Here, auto-complete is off in all input field except in Email.


<form action="" autocomplete="off" >
  First name:<input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  E-mail: <input type="email" name="email" autocomplete="on"><br>
  <input type="submit">
</form>
Don’t miss out!
Subscribe to My Newsletter
Invalid email address