Disable CSS Autocomplete

Is it possible to use CSS to disable autocompletion of a form element (in particular, a text field)?

I am using a tag library that does not allow an autocomplete element, and I would like to disable autocomplete without using Javascript.

+85
html css html-form forms
02 Feb '10 at 17:44
source share
7 answers

You can use the generated id and name each time, which is different, so the browser cannot remember this text field and cannot offer some values.

This is at least an alternative to cross-browser, but I would recommend going with a response from RobertsonM ( autocomplete="off" ).

+45
Feb 02 '10 at 17:49
source share

In a way, there is no autocomplete off attribute in CSS. However, html has simple code for this:

 <input type="text" id="foo" value="bar" autocomplete="off" /> 

If you are looking for an effector for the whole site, it will be easy to simply run the js function through all the "input" and add this tag or look for the corresponding / id css class.

The autocomplete attribute works fine in Chrome and Firefox (!), But see also Is there a valid W3C way to disable autocomplete in HTML form?

+119
Feb 02 2018-10-02T00
source share

you can easily implement jQuery

 $('input').attr('autocomplete','off'); 
+47
Dec 28 '11 at 4:24
source share

If you use form , you can disable all autocomplete with

 <form id="Form1" runat="server" autocomplete="off"> 
+14
Jan 22 '14 at 22:10
source share

CSS does not have this ability. You will need to use client side scripts.

+13
Feb 02 '10 at 17:45
source share

Thanks to @ahhmarr, I was able to solve the same problem in my Angular + ui-router > environment, which I will share here for those who are interested.

In my index.html I added the following script:

 <script type="text/javascript"> setTimeout(function() { $('input').attr('autocomplete', 'off'); }, 2000); </script> 

Then, to capture state changes, I added the following to my root controller:

 $rootScope.$on('$stateChangeStart', function() { $timeout(function () { $('input').attr('autocomplete', 'off'); }, 2000); }); 

Timeouts are for rendering html before using jquery.

If you find a better solution, let me know.

0
Sep 05 '16 at 15:28
source share
 $('input').attr('autocomplete','off'); 
-four
Aug 28 '14 at 9:37
source share



All Articles