Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save niksumeiko/360164708c3b326bd1c8 to your computer and use it in GitHub Desktop.
Save niksumeiko/360164708c3b326bd1c8 to your computer and use it in GitHub Desktop.
Disable HTML form input autocomplete and autofill

Disable HTML Form Input Autocomplete and Autofill

  1. Add autocomplete="off" onto <form> element;
  2. Add hidden <input> with autocomplete="false" as a first children element of the form.
<form autocomplete="off" method="post" action="">
    <input autocomplete="false" name="hidden" type="text" style="display:none;">
    ...

This formation is going to prevent Chrome and Firefox to offer autofill and autocomplete for all input fields inside the form.

@nekrapula99
Copy link

You dont want to remove the name and ID attribute. What good would the input field do at that moment. I have version 91.0.4472.77 and its working great. (What I put above)

How do you implement it? I put this but still does not working in Chrome Version 91.0.4472.124

Please help!

@AMBULATUR
Copy link

None of these suggestions works, any other solutions?
Chromium 91.0.864.59

@CavalcanteLeo
Copy link

CavalcanteLeo commented Jun 28, 2021

@AMBULATUR

try it like google and facebook do:

google:

<input class="gLFyf gsfi" jsaction="paste:puy29d;" maxlength="2048" name="q" type="text" aria-autocomplete="both" aria-haspopup="false" autocapitalize="off" autocomplete="off" autocorrect="off" autofocus="" role="combobox" spellcheck="false" title="Pesquisar" value="" aria-label="Pesquisar" data-ved="0ahUKEwjw0svW6brxAhWdqJUCHXoYDRsQ39UDCAQ">

facebook:

<input type="search" dir="ltr" aria-autocomplete="list" aria-expanded="true" aria-label="Pesquisar no Facebook" role="combobox" placeholder="Pesquisar no Facebook" autocomplete="off" name="global_typeahead" spellcheck="false" aria-invalid="false" value="" class="oajrlxb2 rq0escxv f1sip0of hidtqoto e70eycc3 lzcic4wl hzawbc8m ijkhr0an aaoq3grb sgqwj88q b3i9ofy5 oo9gr5id b1f16np4 hdh3q7d8 dwo3fsh8 qu0x051f esr5mh6w e9989ue4 r7d6kgcz br7hx15l h2jyy9rg n3ddgdk9 owxd89k7 ihxqhq3m jq4qci2q k4urcfbm iu8raji3 qypqp5cg l60d2q6s hv4rvrfc hwnh5xvq ez2duhqw aj8hi1zk r4fl40cc kd8v7px7 m07ooulj mzan44vs" aria-controls="jsc_c_3n">

If you notice, both have removed ID attribute

Captura de Tela 2021-06-28 às 14 15 19

Captura de Tela 2021-06-28 às 14 15 25

@AMBULATUR
Copy link

@CavalcanteLeo,
works extremely great, ughm, btw Autocomplete works really weird, some1 should really report a couple of cases to chromiumGroup when autocomplete is not needed from the word at all .

@CavalcanteLeo
Copy link

CavalcanteLeo commented Jun 28, 2021

@AMBULATUR i just copied the code directly from developer tools.

Now, try to remove all unnecessaries things, one by one, and test it

@andrebrian98
Copy link

@CavalcanteLeo You have an example of the last solution similar to google or facebook, I tried to replicate it but I was not successful, thanks

@CavalcanteLeo
Copy link

@andrebrian98 try to copy direct from facebook/google source code

@sescotti
Copy link

@vicn1222
Copy link

Nothing works, don't waste your time and let it be. I spend enough time trying this and that!

@ryanconnaughton
Copy link

ryanconnaughton commented Aug 19, 2021

What worked for me on a city input (as I'm using a custom React autocomplete component instead):
<label for="this-isnt-checked-against">
C<span style="display: none; >\</span>ity
</label>
<input autocomplete="off" autofill="off" name="anything-but-a-keyword-the-browser-may-check-against" />

@Mekacher-Anis
Copy link

Mekacher-Anis commented Aug 25, 2021

I solved this problem with this "hack"

<input type="email" name="hidden" id="hidden" style="width: 0; height: 0; border: 0; padding: 0" />
<input type="password" name="hidden" id="hidden" style="width: 0; height: 0; border: 0; padding: 0" />

add those lines before the actual inputs that you want the use to fill
so let chrome fill in a hidden field, that doesn't bother me :P

@travisapple
Copy link

The only thing that worked for password inputs on everything is to use type="text" and then swap out the font with this:

@font-face {
  font-family: 'password';
  font-style: normal;
  font-weight: 400;
  src: url(https://jsbin-user-assets.s3.amazonaws.com/rafaelcastrocouto/password.ttf);
}

#loginpass {
  font-family: 'password';
}

It's the only real future-proof solution on this entire page after 4 years. Any hack you try is going to by disabled at some point by google because they don't want you to be able to do this on their browser.

@zmitic
Copy link

zmitic commented Oct 13, 2021

For those who stumbled here like I did many times, this works (at least for now):

<input role="presentation" autocomplete="off" />

You don't need to delete ID or have dynamic names.

@phalakgirish
Copy link

autocomplete="new-password"

Its works thanks

@rcotrina94
Copy link

@zmitic solution worked for me. Thanks!

@Desant2005
Copy link

Thanks!

@saidMounaim
Copy link

saidMounaim commented Oct 22, 2021

@iamaks1993
Copy link

@axelf
Copy link

axelf commented Nov 19, 2021

Check out this article

https://adamsilver.io/blog/stopping-chrome-from-ignoring-autocomplete-off/

This only works in Chrome. Firefox ignores the autocomplete value other than "off".

@luckluster
Copy link

Could it be that the Google Chrome team is reading this page and uses it to still show that damned address autocomplete?

It's damn stupid because the Google Chrome autocomplete is covering the Google Maps autocomplete we're using.

@jsivelopment
Copy link

Any GOOD solution?

@fpenbegul
Copy link

any current solution?

@eduardo-mior
Copy link

@ElvisAns
Copy link

ElvisAns commented Dec 15, 2021

I've used this prop alongside my input field attributes (: it has worked!! : aria-autocomplete="both" aria-haspopup="false" autocapitalize="off" autocomplete="off" autocorrect="off" autofocus="" role="combobox" spellcheck="false"

@Shylmysten
Copy link

Shylmysten commented Dec 21, 2021

I was having the same issue here, and although this is not the most elegant solution, it's just a few lines of code and it seems to work for now...

@Westie solution seems to have been completely overlooked here by everyone... not sure why, but it seems to do the trick.

jQuery(document).ready(function() { 
         jQuery('input').each( function() { 

               // Add your read only attribute and remove it onClick/focus
                jQuery(this).attr('readonly', 'true').attr('onClick', "this.removeAttribute('readonly');"); 

               // Reintroduce the readonly attribute on mouseleave
                jQuery(this).on('mouseleave', function() {
                      jQuery(this).attr('readonly', 'true')
                });
         });
 }); 

@jarrisondev
Copy link

i use the value none and this function for me, i tried with off but doesnt function

<input
   type='text'
   autoComplete='none'
/>

@njfamirm
Copy link

thanks

@piyush-wohlig
Copy link

how to stop autofilling in v-text-filed

@andrei-gheorghiu
Copy link

@zmitic you rock, man. This should be more visible.

@jirihradil
Copy link

@zmitic Thank you, role="presentation" works for Chrome Version 97.0.4692.99 (Official Build) (arm64)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment