How to disable autocomplete in HTML?

Posted underHTML

The autocomplete feature has been of a great help as a website visitor especially if you have a long form that you might fill more than once. The autocomplete feature of HTML is basically used to fetch previous input values from the input field. However, not every time do you require autocomplete. Consider an input that requires some kind of sensitive data like password, credit card numbers etc. In such cases you might ideally want the autocomplete to be turned off. Through HTML you can easily turn off the autocomplete.

To disable autocomplete or to disable autofill in HTML you need to set the autocomplete attribute of input elements to off. You should add it as an attribute on the input element. So your code now should look similar to the following :

<input type="text" name="firstname" autocomplete="off" >

How to disable or turn off autocomplete in jQuery ?

You can turn off the autocomplete feature even through jQuery. Basically the concept remains the same as that of HTML. However, instead of you manually adding autocomplete="off" to each and every input field, you can use jQuery to do it for you. All you need to do is to target the element using jQuery selector and add the autocomplete attribute and its value. So you can turn off the autocomplete in jQuery through the following code :


Or you can also target all the input elements with autocomplete attribute in it and turn it off using the following :


However, please remember that the autocomplete attribute would turn off the suggestions from the previous input values alone. If you have a autocomplete plugin or your browser has an explicit autocomplete feature (like chrome’s inbuilt autocomplete), then not necessarily the autocomplete attribute might be considered and hence you might not be able to turn the autocomplete off using the attribute.

Also sometimes you need to disable autocomplete in html form by setting the autocomplete="off" attribute on <form> element like <form autocomplete="off" > . This helps to get rid of certain plugin or browser based autocomplete features like the one in Chrome browser.

Happy Coding ! Let us know if it worked for you.

TaggedautocompleteHTMLHTML5jQuery – Read tutorials related to JavaScript, jQuery, HTML5, CSS3 and more !

Cover Image for How to check if checkbox is checked in jQuery?

How to check if checkbox is checked in jQuery?

It is very easy to check if a checkbox is checked in jQuery using the .is() or .prop() method of jQuery combined with the ‘:checked’ selector. There are other ways too like checking for the attribute checked value, however, they aren’t very reliable. The easiest and most stable way to check if checkbox is checked … Read more

Cover Image for [Solved] Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’

[Solved] Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’

You might be facing an “Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’ ” error if you are using the react-router-dom package version 6. This error is caused due to using the older switch syntax of the react-router-dom. From version 6 onwards, the react-router-dom has replaced “Switch” with “Routes”. Let us take a look … Read more