Disabling Chrome Autofill
Asked Answered
D

68

618

I have been running into issues with the chrome autofill behavior on several forms.

The fields in the form all have very common and accurate names, such as "email", "name", or "password", and they also have autocomplete="off" set.

The autocomplete flag has successfully disabled the autocomplete behavior, where a dropdown of values appear as you start typing, but has not changed the values that Chrome auto-populates the fields as.

This behavior would be ok except that chrome is filling the inputs incorrectly, for example filling the phone input with an email address. Customers have complained about this, so it's verified to be happening in multiple cases, and not as some some sort of result to something that I've done locally on my machine.

The only current solution I can think of is to dynamically generate custom input names and then extract the values on the backend, but this seems like a pretty hacky way around this issue. Are there any tags or quirks that change the autofill behavior that could be used to fix this?

Dowager answered 1/4, 2013 at 5:45 Comment(17)
Please complete (and clarify) the sentence “Chrome autopopulates the fields as”. What do you mean by “auto-populate”, which seems to mean something else than autocomplete? Also please provide a self-contained demo and/or URL of a demo. It sounds like the issue is caused by some JavaScript code on the page or by some Chrome add-on.Crossfertilize
@JukkaK.Korpela Autocomplete looks like this where it suggests values as you type. The auto populate looks like this where when the page loads, chrome detects inputs and guesses what values to fill them with, as well as coloring the backgrounds yellow. In my case it is guessing incorrectly.Dowager
possible duplicate of Google Chrome form autofill and its yellow backgroundCrossfertilize
It's not a duplicate. This one handles disabling the autofill, that one handles styling the autofill color ...Cobble
autocomplete="false" instead of autocomplete="off" as per Kaszoni Ferencz answer, get voting for it people.Conciseness
possible duplicate of How do you disable browser Autocomplete on web form field / input tag?Paulinepauling
Look at the number of answers to this question - it should tell you something: you're fighting a losing battle. This is no longer a Chrome issue, Firefox and others have been following suit. Like it or not, you need to accept the decision of the browser industry, that form auto-complete is the user's choice - you can fight them, but you will lose. At the end of the day, the question you should be asking is not, how can I subvert auto-complete, but rather, how do I create forms that work well with auto-complete. Your concerns about security are not yours to worry about, but the users.Ganof
I agree with @mindplay.dk. Read more about the controversy at groups.google.com/a/chromium.org/forum/#!msg/security-dev/… Even if you get an answer today that works, Chrome devs are probably working to bypass it. It's a twisted version of whack-a-mole.Glasper
Browsers won't likely attain a perfect strategy of autofilling, because there's no standard to identify username/password fields used in login screens. The browsers seem to be using heuristics with type="password" that, although are useful for many true login screens, also produce many wrong attempts to autofill where password (or masked) inputs are used.Glasper
For others stumbling upon this, the best resource to understanding this for me has been this MDN article. In short, autocomplete="just about anything other than on or off" seems to do the trick. developer.mozilla.org/en-US/docs/Web/Security/…Viaticum
autocomplete="off" works.... For me: <input id="q" type="text" data-bind="textInput: q" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" role="textbox">Plague
Sorry, but @mindplay.dk's response is counter-productive. My situation is I have users who have logged into my site and a page on the site is for them to enter account/pwd information for other systems. When I put up a diaog for them to enter a new one, their logon info for my site gets filled in, which is completely wrong and will cause problems if/when users inadvertently enter that information in. The two have nothing whatever to do with each other. In this case the browser is doing something counter to what the user wants.Fabric
Note that if your <form> tag has autocomplete="on", then it will override autocomplete="false" for individual form elementsBriefs
@Ganof - My web application is a workflow management application for the workplace, so, no, the concerns about security are mine to worry about, as mandated by top management and must be adhered to by all employees, aka "the users." However asking them to set Chrome, IE, or any other browser themselves is going to leave gaps in the authentication process, since they can, intentionally or not, wind up using the autofill. ANot all web applications are of the same type, with the same kinds of users or concerns.Finespun
By having placeholder = " " resolved issue for me in chrome. In html you can do this: <input id="email" class="validate" type="email" placeholder=" ">. While MVC code would be like this: @Html.EditorFor(s => s.Password, "Password", new { htmlAttributes = new { @class = "validate", @id = "pass", placeholder = " " } }). You can use Html.TextBoxFor instead of EditorFor if required.Carpal
This is pretty annoying. I have a too complex SPA and Chrome is randomly detecting wrongly several inputs around the views as email inputs, I have no clue why. And I find no way to disable it. It even broke some features, mainly related to filtering, masking or validation (since in some of them, Chrome thankfully writes down wrong content on behalf of the user). Going to star this issue.Stadler
Sadly, the correct answer is (realistically) just "no, it can't be done in a reliable way." It's quite clear that Chrome doesn't want websites to be able to disable this, so anything that does work in the interim is likely to be disabled in a future release again.Intergrade
D
1320

June 2023: autocomplete="one-time-code" works in Chrome https://robindirksen.com/blog/html-autocomplete-one-time-code

Apr 2022: autocomplete="off" still does not work in Chrome, and I don't believe it ever has after looking through the Chromium bugs related to the issue (maybe only for password fields). I see issues reported in 2014 that were closed as "WontFix", and issues still open and under discussion [1][2]. From what I gather the Chromium team doesn't believe there is a valid use case for autocomplete="off".

Overall, I still believe that neither of the extreme strategies ("always honor autocomplete=off" and "never honor autocomplete=off") are good.

https://bugs.chromium.org/p/chromium/issues/detail?id=914451#c66

They are under the impression that websites won't use this correctly and have decided not to apply it, suggesting the following advice:

In cases where you want to disable autofill, our suggestion is to utilize the autocomplete attribute to give semantic meaning to your fields. If we encounter an autocomplete attribute that we don't recognize, we won't try and fill it.

As an example, if you have an address input field in your CRM tool that you don't want Chrome to Autofill, you can give it semantic meaning that makes sense relative to what you're asking for: e.g. autocomplete="new-user-street-address". If Chrome encounters that, it won't try and autofill the field.

https://bugs.chromium.org/p/chromium/issues/detail?id=587466#c10

Although this "suggestion" currently works for me it may not always hold true and it looks like the team is running experiments, meaning the autocomplete functionality could change in new releases.

It's silly that we have to resort to this, but the only sure way is to try and confuse the browser as much as possible:

  • Name your inputs without leaking any information to the browser, i.e. id="field1" instead of id="country".

  • Set autocomplete="do-not-autofill", basically use any value that won't let the browser recognize it as an autofillable field.


Jan 2021: autocomplete="off" does work as expected now (tested on Chrome 88 macOS).

For this to work be sure to have your input tag within a Form tag


Sept 2020: autocomplete="chrome-off" disables Chrome autofill.


Original answer, 2015:

For new Chrome versions you can just put autocomplete="new-password" in your password field and that's it. I've checked it, works fine.

Got that tip from Chrome developer in this discussion: https://bugs.chromium.org/p/chromium/issues/detail?id=370363#c7

P.S. Note that Chrome will attempt to infer autofill behavior from name, id and any text content it can get surrounding the field including labels and arbitrary text nodes. If there is a autocomplete token like street-address in context, Chrome will autofill that as such. The heuristic can be quite confusing as it sometimes only trigger if there are additional fields in the form, or not if there are too few fields in the form. Also note that autocomplete="no" will appear to work but autocomplete="off" will not for historical reasons. autocomplete="no" is you telling the browser that this field should be auto completed as a field called "no". If you generate unique random autocomplete names you disable auto complete.

If your users have visited bad forms their autofill information may be corrupt. Having them manually go in and fix their autofill information in Chrome may be a necessary action from them to take.

Dicker answered 22/6, 2015 at 9:18 Comment(90)
'new-password' worked for me after trying 'off' and 'false'Campanile
Worked on Chrome V 44, see documentation here: developers.google.com/web/fundamentals/input/form/…Hydromedusa
This is the only working fix now. False, and off, do not work anymore. Should be the correct answer now.Whist
Works for Version 44.0.2403.130 m - only thing that worked for me!Naashom
This does not work for me, chrome still auto fills lastname and password for new accounts. chrome is ignoring autocomplete attribute.Alodium
It worked for me but you have to assign it to a specific input element. It will not work if you apply this to the <form> element.Beekman
Works 100%. Simple and effective. Thank you so much, tested on 50.0.2661.94 mRosenblast
Unfortunately Chrome then asks the user to save the changed password when the form is submitted/hidden.Schertz
Works in Version 51.0.2704.79 mJosiejosler
Not working for me (on mobile, non-password field). Shows up as autocomplete="off" in the HTML, which of course doesn't work.Vibrio
Worked perfectly on Chrome 51.0.2704.103 m (64-bit)Mastoidectomy
It prevent autofill, but how to disable autocomplete for password fieldHeterogeneity
@Daniel, works in Version 52.0.2743.116 (64-bit) on macOS (10.12 Beta (16A304a)) - At least for me.Ragman
After 2 hours trying other suggestions this works! Chrome 54.0.2840.71Michelemichelina
The reason this works is because the chrome team are trying to create recommended autocomplete values, as shown @ developers.google.com/web/fundamentals/design-and-ui/input/… The "new-password" value is one of the few that have additional logic surrounding it, and in this case, its to suspend autofill but still allow autocomplete suggestionsMichelemichelina
Setting autocomplete="new-password" is the only thing that worked for me.Margrettmarguerie
This answer works for me **** 6/5/2017 *** Version 58.0.3029.110 (64-bit)Sensorium
This did not work as of 8.30.2017 Version 60.0.3112.113 (Official Build) (64-bit)Bonus
For react: autoComplete="new-password"Remake
Not working as of 1.13.2018 Version 63.0.3239.132 (Official Build) (64-bit)Iives
is working with react 16, Chrome version 64: 'new-password' , I' don't know if work without reactExceptional
works like a charm Version 64.0.3282.186 (Official Build) (64-bit)Rame
worked in Vue until I updated and memorised the password on the login view again now it's started autofilling again.Wack
For my text input not used for password works this: <input id="townInput" type="text" name="town-name" autocomplete="new-town-name" autocorrect="off">Bole
Does not work for me with React and Meteor. Chrome Version 66.0.3359.139Dunnage
I copied autocomplete="off" from google map, and it works on chrome version 66.Mucronate
Autocomplete and autofill are not the same. Using the autocomplete attribute will NEVER disable autofill. I'm guessing that's why this isn't working for half of you. Autofill can only be disabled through the browser settings.Mcclellan
autocomplete="off" is working again now as of Chrome Version 68.0.3440.106 (Official Build) (64-bit)Adornment
It's worth noting that to solve the OP's problem, you don't need to disable autocomplete, you can just give autocomplete labels to tell the browser what type of info the field is for, that way, the right info would more likely go to the right field. See here on the list of autofill attribute values: html.spec.whatwg.org/multipage/…Mystify
Note: Not every browser has implemented the more specific autofill values, see this page where were they tested which browsers used what to identify fields: cloudfour.com/thinks/…Mystify
Doesn't work anymore. A working 'solution' (for me) is supplied here: #12374942Levitation
Original bug has been marked as won't fix. Someone has reopened here bugs.chromium.org/p/chromium/issues/detail?id=914451 please star it if you think this should be fixed.Cameliacamella
I am not working within a form and I have an input field showing a date in a UL how can I get this to work? THe autocomplete="new-password" still does not stop the autocomplete from trying to fill it in.Successful
As I learned, autocomplete is not autofill. Therefore setting autocomplete does not help to prevent autofill. Autofill uses e.g. label text around the input, and if it matches to something like 'number', credit card information may be suggested. It seems to be impossible to switch off that. My solution was to modify the label with zero-width witespaces. Assume you have your label information available in js, you may use the following simple code: label = label.split('').join('&#8203;'); In HTML you can simply put a '&#8203;' between parts of your label like 'nu&#8203;mber' or 'ca&#8203;rd'.Hagbut
This is the only solution that worked for me. Works in newer versions of chrome tooPitiful
I just wanted to say.. After stumbling across this issue.. Chrome is a real piece of work. So now we must jump through hoops to disable functionality that was supposed to remain optional. In what world would address autofill be needed in a business application where the address is new / different every time. Google is becoming just as bad as Microsoft.Pipistrelle
give name as which field auto populating. .hide-input{ width: 0; height: 0; border: none; position: absolute; } <input type="text" value="" name="username" class="hide-input" />Judd
Here's where the Chrome autofill source code is. chromium.googlesource.com/chromium/src.git/+/refs/heads/master/… Anyone able to dig in and see how it determines fields to target for population? It may be we can defeat the approach it uses as long as we know what the approach is.Lola
This solution is not completely valid. It turns off the autocomplete, but the autofill feature is still intact. Here is the video with the solution: youtube.com/watch?v=tJTaCFdYXrw&feature=youtu.be In order to get rid of both of them, you have to add custom value to the name attribute, set the autocomplete to off, and change the input type to search. And remember the Autofill and Autocomplete are not the same thing in ChromeMindi
Worked for me Chrome Version 75.0.3770.142Mcghee
It only works for password autocomplete="new-password", email (="new-email"), username (="new-username") . For all the other fields that DO NOT have the string ..."blabla-password"... "email-blabla"... "bla-username-bla" in the id or name you must still use 'off' to have the best result!Codel
I was able to get this to work by setting the "name" attribute to Date.now(). I'm using a dynamic input so we don't ever actually use the real name value and it magically worked in Chrome 78... for now.Penology
None of the autocomplete attribute values worked for me. I am using Chrome 79.0.3945.88. All I wanted was to disable the autofill suggestion for the password field. I did that by making the input type text in html then changing the type to password in javascript on initialisation of the page. E.g: Html: <input type=text id=myPassword> JS with jquery: $(function () { $('#myPassword').attr('type', 'password')});Pitt
The correct answer is now autocomplete="disabled" off and false values do not work anymoreDong
This no longer works. Once you've provided details for a field before, it will remember, no matter what you call. It. The solution (to trick it), is to change the name="whatever" and placeholder="whatever" to be unique on every load. In my case, I've added a timestamp (secs since epoch) after those. So they become name="whatever1584167734" and placeholder="whatever1584167734". That fixes it. I have my own autosuggest box which was being out-z-indexed by Chrome's autosuggest.Alhambra
Additionally, I'll add that if you're intending on submitting the form more than once on the same page, you'll need to rename the field attributes after each form submission if you want to stop it from happening.Alhambra
Just to add on, giving autoComplete="new-password" to the password field made sure that other fields like username are also not autofilled now. You don't have to add any extra attributes to fields other than passwordDevitt
We run our business on Chrome. It's beyond frustrating that even providing autocomple="someRandomString" no longer works. This needs to be addressed in the standards and Google Chrome needs to adhere to those standards or they too will fall to the sidelines like Netscape Navigator and Internet Explorer.Ogdoad
autocomplete="new-password" won't do the auto-fill, but once you click on the password field you will still get a suggestion prompt. I can't believe that it's been years and they still didn't resolve this.Jakob
autocomplete="new-password" works as per: developer.mozilla.org/en-US/docs/Web/HTML/Attributes/…Frigidaire
Nothing really works here with Chrome. I'm using plain-text boxes now.Adjective
Only autocomplete="off" is working for me with Chrome v.85/85 on MacOS 10.15.Accomplished
This is the only way I could make it work in 2020: #60690257Yokoyokohama
Version 86.0.4240.111 nothing works. I used to get by with a autocomplete="off" and hidden password and email fields on all forms. I have tried "new-password" "chrome-off" "dont-use-autocomplete I-dont-like-it" nothing has any effect and autocomplete continues to show up for random fields. some still don't show it but I can't make heads or tails of why they are not and the others are.Moderator
Running on "86.0.4240.111 (Official Build) (x86_64)" and tried all the above mentioned approaches but nothing worked for me: hidden password field, "chrome-off"/ "off"/ "no"/ any other value for all inputs and the overall form. Very critical for a page if the autofill window actually breaks the hovering logic of the login widget and thus disappears. I'm really angry that the Chrome developers making us a difficult time with this...Minelayer
Hm, Version 86.0.4240.111 (Official Build) (64-bit) on Ubuntu correctly behaviors only with autocomplete="off". Neither "chrome-off" nor "new-password" didn't helpAcidhead
None of the answers work for me. What in the world disables Chrome autofill?Pipeline
autocomplete="chrome-off" is working on my chrome on last osx. We need a consistent solution from google..Sever
My experience involved erroneous autofilling on a lone <input> element, which is valid. When that input element was provided a parent <form> then Chrome 87 stopped erroneously autofilling an input element that clearly had nothing to do with the autofill chrome was using.Wurth
Not working on latest Brave or Edge on Windows. Only thing that works is autocomplete="<anything other than off|on or other valid value>" on every affected field.Skitter
Thanks! But what a load of crap man. autocomplete="off" works for me now in chrome 88, but only for regular inputs. I did not test it on password fields.Bloomers
I'm trying in Chrome 89.0.4389.90 on macOS and it's not working :/Brunhilde
So on Win 10 Chrome 89 my only solace came from prepending the autocomplete property with "new-", eg. <input autocomplete="new-email"/>Diegodiehard
This isn't working in my newest version of Chrome now.Tacklind
As of 2021: this has worked for me, autocomplete="chrome-off"Explication
in some cases none works and in some cases off works :shrug:Imbed
In Chrome 91 on Windows I have not been able to get Chrome to stop auto filling, Neither autocomplete="off" nor autocomplete="chrome-off" workedHitlerism
Version 93.0.4577.82 chrome-off not working anymoreCyrillic
None of the autocomplete options from above work on Version 96.0.4664.45 (Official Build) (64-bit)Disject
Still broken Version 96.0.4664.110 (Official Build) (64-bit)Cohdwell
autocomplete="chrome-off" works for me only if one of the input text elements has it.. if all have it it stops workingBeatriz
I have been setting autocomplete="<random 12 character string>"... obviously not an ideal solution, but its the only way i've been able to consistently turn it offBrittneybrittni
Your update from Sept 2020 did not work for me. Using just "off" worked for me. I'm on Version 97.0.4692.71 (Official Build) (64-bit) of Chrome.Acriflavine
Feb 2022 - None of the suggestions works, even using hidden inputs. I managed to get it working by adding normal inputs and hiding them with height: 0; opacity: 0; margin: 0; padding: 0; (display: none did not work either) Chrome version 98.0.4758.102Contaminate
I found this one. It disables on chrome, edge and opera <form autocomplete="off"> <input role="presentation" /> </form>Dykes
Using autocomplete='whateverrandomvalueyouwant', in other words, using an unrecognized value, is automatically converted to autocomplete='new-password' by chromium and this is apparently now honoured by chrome but not edge.Randalrandall
If you have an input type="password" with chrome Version 103.0.5060.53 (Official Build) (x86_64) The only solution to deny the autofill seems to change the type to "text", give an id/name that is not recognizable as a pwd by chrome, set autocomplete="false" and use css to recreate the "password dots" <input className="textareaProfile centerElement placeholderBlack fakePwd" type="text" id="id2" placeholder='Nuova password' autoComplete="false"/> .fakePwd{ -webkit-text-security: disc; }Linguist
None of these solutions workMentally
autocomplete="disabled" worked for meMalherbe
This works: <input type="text" name="username" autocompleteOff>Drupelet
even a random string for the autocomplete attr doesn't work anymore. Now I have to mangle the Name attribute too to get it to turn off, which I imagine is not ideal for many web applications...Brittneybrittni
I can report that for Chrome 104 (sept 2022), "off" does not work, but autocomplete="chrome_leave_my_field_alone" does work.Mall
UPDATE from September 2022: autocomplete="off" attached with <input type="text" element has started to work perfectly now.Autosuggestion
My inputfield was in a table, its name and id where field1, but it still got auto filled because in the td column before it said adres: Now fixed it with autocomplete="off" on the input, and ::before { content: 'adres'; } on the table cell of the labelOlli
For anyone who does not use forms, you can put a <form action = "javascript:void(0)"></form> around the input to avoid auto completeOlney
I resolved the issue by adding HTML id attributes to my input fields with autocomplete="off". For example, <input type="number" id="thisIsIdJustForPreventAutoFill">. Additionally, When one field has an id attribute, it can determine whether suggestions will be provided for other fields within the formAccost
Absolutely ridiculous. The OBVIOUS use case is creating forms within B2B applications where users can be added and removed. Chrome autofills these inputs with existing emails and passwords, which is completely nonsensical. Browsers enforce far too much in the name of SeCurItY and BeSt PraCtiCes. Let us build. We know what we're doing.Rockaway
Thank you. After trying "off", "new-password", "false" etc. the only working solution was this: autocomplete="one-time-code".Hautegaronne
Bumping into this issue in November of 202., 'off', 'false' and random bits in the autocomplete='[value]' field no longer work on Chrome.Folse
Yeah, I just found it by myself that one-time-code is the only reasonable solution. Wanted to share that, but you did it already :DBewray
A
847

I've just found that if you have a remembered username and password for a site, the current version of Chrome will autofill your username/email address into the field before any type=password field. It does not care what the field is called - just assumes the field before password is going to be your username.

Old Solution

Just use <form autocomplete="off"> and it prevents the password prefilling as well as any kind of heuristic filling of fields based on assumptions a browser may make (which are often wrong). As opposed to using <input autocomplete="off"> which seems to be pretty much ignored by the password autofill (in Chrome that is, Firefox does obey it).

Updated Solution

Chrome now ignores <form autocomplete="off">. Therefore my original workaround (which I had deleted) is now all the rage.

Simply create a couple of fields and make them hidden with "display:none". Example:

<!-- fake fields are a workaround for chrome autofill getting the wrong fields -->
<input style="display: none" type="text" name="fakeusernameremembered" />
<input style="display: none" type="password" name="fakepasswordremembered" />

Then put your real fields underneath.

Remember to add the comment or other people on your team will wonder what you are doing!

Update March 2016

Just tested with latest Chrome - all good. This is a fairly old answer now but I want to just mention that our team has been using it for years now on dozens of projects. It still works great despite a few comments below. There are no problems with accessibility because the fields are display:none meaning they don't get focus. As I mentioned you need to put them before your real fields.

If you are using javascript to modify your form, there is an extra trick you will need. Show the fake fields while you are manipulating the form and then hide them again a millisecond later.

Example code using jQuery (assuming you give your fake fields a class):

$(".fake-autofill-fields").show();
// some DOM manipulation/ajax here
window.setTimeout(function () {
  $(".fake-autofill-fields").hide();
}, 1);

Update July 2018

My solution no longer works so well since Chrome's anti-usability experts have been hard at work. But they've thrown us a bone in the form of:

<input type="password" name="whatever" autocomplete="new-password" />

This works and mostly solves the problem.

However, it does not work when you don't have a password field but only an email address. That can also be difficult to get it to stop going yellow and prefilling. The fake fields solution can be used to fix this.

In fact you sometimes need to drop in two lots of fake fields, and try them in different places. For example, I already had fake fields at the beginning of my form, but Chrome recently started prefilling my 'Email' field again - so then I doubled down and put in more fake fields just before the 'Email' field, and that fixed it. Removing either the first or second lot of the fields reverts to incorrect overzealous autofill.

Update Mar 2020

It is not clear if and when this solution still works. It appears to still work sometimes but not all the time.

In the comments below you will find a few hints. One just added by @anilyeni may be worth some more investigation:

As I noticed, autocomplete="off" works on Chrome 80, if there are fewer than three elements in <form>. I don't know what is the logic or where the related documentation about it.

Also this one from @dubrox may be relevant, although I have not tested it:

thanks a lot for the trick, but please update the answer, as display:none; doesn't work anymore, but position: fixed;top:-100px;left:-100px; width:5px; does :)

Update APRIL 2020

Special value for chrome for this attribute is doing the job: (tested on input - but not by me) autocomplete="chrome-off"

Update JUNE 2023

Use autocomplete="new-password"

This is working currently.

Ambriz answered 10/4, 2013 at 4:54 Comment(88)
Thanks for sharing this info. Was having this very same weird behavior and wasn't understanding why it happens until you clarify. On my case, it only happened when I turned autocomplete="on". That was why I wasn't experiencing this issue before.Gilboa
Excellent answer for the reason. For the solution, I'm trying this, as well as https://mcmap.net/q/57966/-disable-form-autofill-in-chrome-without-disabling-autocomplete-duplicate/292060. I'd prefer to turn off autofill, but keep autocomplete.Viand
I was so sure this would work as you explained perfectly the heuristic autofill I'm experiencing with input before password field. Unfortunately, it didn't work for me, I put autocomplete="off" on both the form and all the inputs and they still get filled. The only solution that worked for me is in goodeye's link above. (placing a second hidden type="password" input before the password throws off chrome's heuristic checks)Vara
This used to work fine, I used it too, but since a Chrome upgrade some time ago (between then and May 5th), Chrome ignores the form property :(Improbity
Google took the decision in (Chrome v34 I think) to make it policy to ALWAYS now ignore autocomplete="off", including form level directives ... that would be fine if it actually got the damn fields right.Origen
Thanks for the comments, I've tried it again myself also and agree my old solution no longer works, so have updated with the latest solution.Ambriz
It is incredibly annoying that google decided to make chrome ignore the autocomplete attribute - it kept autofilling a user record edit form with the admins login details until I found your work around. Thanks.Mcspadden
The solution does indeed work but it's ridiculous that such a kludge is even necessary. When a dev codes autocomplete=off into a form, it's usually for a good reason. No means no, Chrome! Discussion of the issue: code.google.com/p/chromium/issues/detail?id=352347Ceratoid
you can remove the name attributes so these fake params aren't posted to serverPrimogeniture
Thanks for the workaround. I had to change a bit by putting the fake username before the real one and fake password after the the real one.Cysto
@Cysto - why did you have to do that? It usually works fine having both fake user and fake password before the real ones.Ambriz
@mikenelson It didn't work for me, Chrome picked up the fake username + the real password. Btw, I'm using Chrome 39.Cysto
@Ceratoid The reason all browsers had to start ignoring it is because developers would put it there without good reason. E.g. Managers, lawyers, legal department, HIPAA, and Sarbanes–Oxley are not valid reasons to disable autocomplete. But that didn't stop developers from bowing to pressure from the U.S. government. The better way to not auto-complete passwords is to tell Chrome to not remember your password.Heracles
Even better: remove the name="" attributes on both inputs and that information never even gets posted to your server, but it still fools Chrome.Cohby
Yes it does. I just used the above solution. And your jsbin works as well. Chrome 41. :)Aedes
This will become a big security issue ?? If the user mistakenly click the "save password", and he doesn't view any passwords on the login textboxes. He will think that there's no password saved. but its still saved, and recoverable by Javascript :/Cathrin
Hi guys, this solution doesn't work. Tried on both Chrome 41 and 42. So I twisted the hack by inserting invisible spans into the label instead. It worked beautifully on Chrome 41 and 42. - <label for="address">Registered Add<span style="display:none">This is to make Chrome to not autocomplete</span>ress: </label>Synn
try autocomplete="false" not autocomplete="off"Conciseness
This attribute is also required: autocomplete="I told you I wanted this off, Google. But you would not listen."Airy
It worked for me even without name attribute. But I had to add non-empty value attributes to prevent FF (38.0.5) from autocompleting these hidden inputs.Dehorn
@MagnusEriksson: No. The jsbin does not work. Chrome 43.0.2357.134Pedicular
Yes, I can confirm that next to the 2 fake fields, you need autocomplete="off" in your form element. This is hilarious :)Endogenous
@Conciseness what autocomplete=false did not make it work. Its the same as autocomplete=off, chrome doesnt careMagnificence
This poses a huge and serious security exposure. Any site can harvest usernames and passwords, ip addresses from the client, and a host of other _SERVER variable info. I just proved it on my site by looking at the _POST vars submitted. And I thought Google was smart. Fooled me.Fibriform
This is both the most effective way but the worse hackish way. It's how the web works: not good job, clean job. No. Hacks, hacks, hacks, hacks, hacks, hacks, hacks, hacks. I'm fed up with that.Altricial
It looks like this just stopped working in Chrome v48.0.2564.82 mLeroylerwick
Yes it stopped working - it's like an arms race. I solved it with: <div style="height:0; overflow: hidden;"> <input type="text" name="fakeusernameremembered"> <input type="password" name="fakepasswordremembered"> </div>Background
@AdamJimenez, the problem with your solution is that a person can Tab into the invisible field, which is not a good thing. I got it working with solution by hyper_st8 below.Leroylerwick
@VictorF Ahh, thanks for the heads up I will use that also. It's like an arms race!Background
@mikenelson: any idea why the solution (fakeusernameremembered) works?Justiciar
Small comment: I've noticed it only works if the fields were AFTER my real fields (ie Chrome was taking the last field to autofill)Dispensation
@Dispensation So that worked for me, until I updated to v49 today. It seems like they reverted back to only working if you put it before the real fields. Can't seem to win. Not sure what is up with their developers constantly f'ing with this. People complain about IE, but man, they are making themselves look just as bad. Anyway I've now added these fake fields to before and after the real fieldsBrownie
This appears to be broken now on version Version 49.0.2623.110 m. Testing: cleared all passwords for the domain, logged in on one form and saved the password, went back to my create account form and the fields were filled in and the hidden fields were still there. Chrome is painful!Equilibrium
This worked for me, but only after I named the fields the same as the existing fields (name="email" / name="password"). It made no difference where the fake fields are in the form (I placed them at the top). Input type also doesn't seem to matter (works with no type tag). My Chrome version is 50.0.2661.102 m.Indiscrimination
I concur with @Indiscrimination - there have been changes to Chrome and the style="display:none" trick now only works if you use the correct input name (e.g. name="email"). You don't need a password field, it seems.Airy
If I add the two hidden fields above, Chrome fills it in and then carries on and fills all the rest in as well! Wtf ChromeStraightout
This does not work. Use autocomplete="new-password" (https://mcmap.net/q/57902/-disabling-chrome-autofill). Verified works in Version 51.0.2704.79 m.Josiejosler
July 20 2016, neither this nor new-password are working for me on mobile for a non password field. Tried matching name, putting hidden fields both before and after, and JS hack. Chrome 51.0.2704.81Vibrio
It stinks that there is not a better solution than this... (no offense to you @mikenelson) offense to google chrome.Fairhaired
This stopped working for me as of Chrome 56. It started autofilling passwords for non-matching field names. Changed both inputs from style=display:none to style="visibility:hidden;height:0;width:1px;position:absolute;left:0;top:0". Thanks to @digital_flowers and @CodeSimian answers.Seaddon
Stopped working on Chrome 56.0.2924.87 . But the autocomplete="off" on the input worked.Meade
the fake fields need to be after your real user/psw fields in dom - works in any browser (win & mac) for me.Cease
NONE of these solutions, whether it's an answer or something in the comments, are working for me as of Chrome 59. Does anyone have any other suggestions?Anomalism
Having problems with Chrome 59 as well.Sherbrooke
I was able to get this working again. style="height:0px; opacity:0"Acerb
Tried this in Chrome 60 and doesn't appear to work :(, feels like IE hacking all over again...Bonus
This doesn't work in Chrome 61 as well. Has anyone found any solution to this?Capacitor
Thanks for the pointer of "a password field and the field before it" - worked out, when i changed the input so it was no longer a password field.. The users will have to suffer the inconvenience of seeing their new password, but at least I don't have to implement a password/confirmpassword pair :)Checkered
This no longer works, frustratingly. I have a 'change password' form, and Chrome offers offers Use password for on every single one of them, no matter what I've tried including this.Millardmillboard
The of using fields with display:none does not work anymore since Chrome 66. Chrome will not autofill if not displayed. You now have to make it invisible. Set the width, height and border to 0 and background transparent (rgba(0,0,0,0))Apologetics
@Ceratoid "it's usually for a good reason" It's often for a bad reason (security). Hence, the arm race.Iodic
@mikenelson thanks a lot for the trick, but please update the answer, as display:none; doesn't work anymore, but position: fixed;top:-100px;left:-100px; width:5px; does :)Further
@mikenelson Since the autocomplete attribute doesn't seem to be doing much lately, I posted an answer which seems to be working, at least for me and the ones who tested it. This question has so many answers I feel like it won't ever be seen. If you deem it good, would you mind adding it to your post? Thank you :)Fumed
@zennoo - your onfocus trick sounds like a good way to disable the autocomplete dropdown that usually appears whereas we are trying to disable autofill which is where it highlights eg Email fields in yellow and puts your email address in them before you even focus the field. Changing the field name does not prevent this behaviour unfortunatelyAmbriz
You have to make sure the input has a name or id. The browser binds what to autocomplete via attribution. Once you do that, autocomplete='false' should work fine.Euphonium
Sorry... meant autocomplete='off'Euphonium
@CamTullos, it's true that autocomplete binds to the name attribute. But autocomplete off is doing nothing. You changed the name attribute and therefore no autocomplete values are bound yet.Mcclellan
autocomplete="off" is working again now as of Chrome Version 68.0.3440.106 (Official Build) (64-bit)Adornment
With chrome 69.xxx, I done that to remove stop autocomplete <input type="text"><input type="text" style="display:none"><input type="password"><input type="password" style="display:none">Dielle
You should edit the question, autocomplete="off" works fine in todays Google Chrome.Woll
It doesn't work in 70.0.3538.77 (Official Build) (64-bit) @Esko. I think it is safe to say that the Chrome team really doesn't care about a valid use case where you want the auto complete off: in a web app's settings page where you want the user to type in a new email address for their account (the user want's to change the email address on their account)Voss
A new approach that I have not seen: The autofill menu in chrome relies on the input type name.Tobias
A new approach that I have not seen: The autofill menu in chrome relies on input type name. Generating and storing a random number for the name prior to form creation then filtering it out if you need to use the name dynamically and upon form submission. Example: <?php $random_num=date().time()*mt_rand(); ?> <input type="text" name="name<?php echo $random_num;?>"> name=name5904923992050214 which would disable the chrome autofill menu from appearing. Since we filtering out 5904923992050214 we can still use the name. This method should work for dynamic language forms.Tobias
But the suggest will popup as usual when I focus a password type input.Iolite
It might sound really odd, but autocomplete= "new-password" only worked for me if the name of the input was name="password" .My previous name was name="old-password" and changing it did the trick. I hope it helps you ;)Greenery
I've just used <form autocomplete="off"> in chrome and it works for mePals
As I noticed, autocomplete="off" works on Chrome 80, IF there is less than 3 elements in <form>. I don't know what is the logic or where the related documentation about it.Saccharin
autocomplete="something-here" used to work but not anymore. Also tried the autocomplete="chrome-off" and it doesn't work either. Just seems like another variation of adding some gibberish for the parameterIntestate
chrome-off worked for me in Chrome 81. Also - how is everyone doing? I've had 2 kids since I first came to this question. Stay healthy!Padishah
Just tried chrome-off, didn't work for me, wtf! Chrome 81Samaveda
Update Chrome version 83 - chrome-off does not work, however, using a dummy password field along with the styles seems to work as Mike Nelson mentioned. <input type="password" id="dummy-pwd" style="position: fixed;top:-100px;left:-100px; width:5px;"> Just make sure this input field is of type password and it should be placed BEFORE the real password field. What happens here is the autofill finds the FIRST input field of type password and fills it. In jquery $('#dummy-pwd').val() returns the "autofilled" password while the real password field is empty.Haldis
@Haldis Tried it. It doesnt work neither...Its like password manager (no autofill) doesnt give a fuck about how many password inputs you put. It appears for every input you have if it is of type password, simple as that. If you give him the order to store the password you used before, it will always shows to let you choose the passwordRebbeccarebe
I noticed that you also need to pay attention to the name attribute of your input. I also named it using new-something-something pattern and it seems to have helped. I missed that previously, as AngularJS assigns the name on-the-fly basing on ng-model value.Greathouse
regarding the new-password, you can read here the expected behaviour. Scroll to "The autocomplete attribute and login fields". developer.mozilla.org/en-US/docs/Web/Security/…Gregoire
Hello. Had to use autocomplete="off". Chrome version 85+.Aardvark
Here are two Chrome issues you can comment on if you want them to change this behavior: bugs.chromium.org/p/chromium/issues/detail?id=587466 and bugs.chromium.org/p/chromium/issues/detail?id=914451Bourse
People are misunderstanding something. off, chrome-off, whatever are all just strings. They don't have special meaning in this context. I think autocomplete attribute acts like the name field, but for autocomplete. Google just saves your previous form submit with this autocomplete string.Fifi
For people using the fake hidden field remembrer to to add a tabindex="-1" to avoid the tab disappearing.Mareld
I get good explaination here developer.mozilla.org/en-US/docs/Web/Security/…Coenosarc
2018th solution works in 2020 for me.. Thanks for such a long answer!!Totipalmate
This worked for me: Setting <form autocomplete="chrome-off"> <input id="password" style="position: fixed;top:-100px;left:-100px; width:5px;" type="password" name="password"> <input type="password" autocomplete="not-at-all" id="actualPassword"/> </form>Carpology
None of these work for me, I give up. Congratulations Chrome you win.Tease
instead of autocomplete="off" set autocomplete="new-password" for all <input> you want to stop auto-fillingDrawknife
new-password, works see developer.mozilla.org/en-US/docs/Web/HTML/Attributes/…Dorey
as said in this comment (#15738759) adding role="presentation" to the input fields makes autocomplet="off" works also for address autofillsKaryotype
I'm hoping this is helpful. I implemented the following CSS. The Chrome Autofill attempts to load the cached values, but disappears on mouse hover. It's not ideal from a UX perspective, but it's the only thing that seems to work effectively.input:-webkit-autofill { display: none; }Kopeisk
autocomplete="new-password" works if input don't have id like password or current-passwordCribble
The issue with <input autocomplete="chrome-off" /> is that firefox only works with "off" value. By setting <form autocomplete="off"> will disable auto complete for the entire form in firefox, and will co-exist with inputs having the chrome-off value.Sunglass
K
294

After months and months of struggle, I have found that the solution is a lot simpler than you could imagine:

Instead of autocomplete="off" use autocomplete="false" ;)

As simple as that, and it works like a charm in Google Chrome as well!


August 2019 update (credit to @JonEdiger in comments)

Note: lots of info online says the browsers now treat autocomplete='false' to be the same as autocomplete='off'. At least as of right this minute, it is preventing autocomplete for those three browsers.

Set it at form level and then for the inputs you want it off, set to some non-valid value like 'none':

<form autocomplete="off"> 
  <input type="text" id="lastName" autocomplete="none"/> 
  <input type="text" id="firstName" autocomplete="none"/>
</form>
Kamerun answered 11/4, 2015 at 19:57 Comment(22)
It does work very well Aaron, in all major browsers ;)Kamerun
Worked for me! But there is one important remark: I have 5 fields in my web page: Name, Address, Zip code, Phone and Email. When I included autocomplete='false' on the Form and on the Name field, it still worked. However, when I included the autocomplete='false' also on the Address field, it finnally stopped autofilling them! So, you need to put the autocomplete property not on the login or name field, but on the following fields too! (Worked on Chrome 43.0.2357.81 as of 2015-05-27)Dominus
IF THIS DOES NOT WORK FOR YOU: Keep in mind that there are 2 ways Chrome "helps" users. AUTOCOMPLETE will prompt based on previous submission in the same form filed and will affect people who are using the form more than once. Autocomplete is disabled with autocomplete="off". AUTOFILL will prompt based on the address book from previously filled out similar forms on other pages. It will also highlight the fields it is changing. Autofill can be disabled with autocomplete="false".Calesta
This doesn't work for me (Version 43.0.2357.124 m). This was probably an oversight by Google, which has now been resolved. They seem to be thinking "the user is always right" in that they want to autofill everything. The problem is, my registration form saves the user data just like the login form does, which is most definitely not what the user wants...Airy
YEP It works in Chrome 43.0.2357!! this behaviour in Chrome is so annoying, and this workaround took me a while to figure out. Thanks for your answer.Relive
It might not work on old browsers, base on a old 2005 post from Scott Hanselman's blog: hanselman.com/blog/…Cloutman
I would not recommend this solution. Setting autocomplete to "false" works in Chrome but FireFox ignores it.Strephon
Noel Abrahams, the question here was about Chrome and not about Firefox!Kamerun
doesnt work with Chrome 44.0.2403.157. How can this feature work and not work with different versions. It is ridiculousEndogenous
This solution briefly worked, I guess. Not so much anymore. At least, not in our angular site.Framework
See my answer here for a reliable workaround: #12374942Silicosis
@GrahamT Might want to check your code, I just updated to 46.0.2490.80 m and it works.Cascara
@Toolkit Works for me on Chrome 46.0.2490.80. I think it's something other than browser version that's the problem.Vibrio
I tried autocomplete="false" and didn't work on Chrome 47.0.2526.106... However when I use: autocomplete="off" in the "form" tag as well as in every "input" tag that works great!Janiecejanifer
I tried all the previously mentioned fixes and none worked for me on Version 47.0.2526.111 (64-bit)Strongarm
This actually killed the entire form autofill options not just the field for me.Whist
FWIW, google's latest explanation: developers.google.com/web/updates/2015/06/…. "In the past, many developers would add autocomplete="off" to their form fields to prevent the browser from performing any kind of autocomplete functionality. While Chrome will still respect this tag for autocomplete data, it will not respect it for autofill data."Schreiner
Does NOT work as of Chrome 75.0.3770.142. Chrome is a mess.Arbiter
I was able to get a modified version of this working in chrome, firefox, and edge. set autocomplete="off" for the Form element set autocomplete to something invalid, like none, for each input element. Note: lots of info online says the browsers now treat autocomplete='false' to be the same as autocomplete='off'. At least as of right this minute, it is preventing autocomplete for those three browsers. <form autocomplete="off"> <input type="text" id="lastName" autocomplete="none"/> <input type="text" id="firstName" autocomplete="none"/> </form>Pachalic
autocomplete="new-password" and not using input name as "password" worked for me.Mont
For some common forms - e.g. username/password, Chrome seems to identify the type attributes of the elements and suggest autofill accordingly, so a workaround for this is to set a form input that would normally be text to number and then after a 500ms setTimeout change the input type back to text.Oatcake
autocomplete="none" this worked for me autocomplete="off" is not working.Polyandry
M
146

Sometimes even autocomplete=off won't prevent filling in credentials into wrong fields.

A workaround is to disable browser autofill using readonly-mode and set writable on focus:

 <input type="password" readonly onfocus="this.removeAttribute('readonly');"/>

The focus event occurs at mouse clicks and tabbing through fields.

Update:

Mobile Safari sets cursor in the field, but does not show virtual keyboard. This new workaround works like before, but handles virtual keyboard:

<input id="email" readonly type="email" onfocus="if (this.hasAttribute('readonly')) {
    this.removeAttribute('readonly');
    // fix for mobile safari to show virtual keyboard
    this.blur();    this.focus();  }" />

Live Demo https://jsfiddle.net/danielsuess/n0scguv6/

// UpdateEnd

Explanation: Browser auto fills credentials to wrong text field?

filling the inputs incorrectly, for example filling the phone input with an email address

Sometimes I notice this strange behavior on Chrome and Safari, when there are password fields in the same form. I guess, the browser looks for a password field to insert your saved credentials. Then it autofills username into the nearest textlike-input field , that appears prior the password field in DOM (just guessing due to observation). As the browser is the last instance and you can not control it,

This readonly-fix above worked for me.

Melvinmelvina answered 14/11, 2014 at 13:32 Comment(19)
what a great fix :) you should replace jquery with this: this.removeAttribute("class")Brom
I used this to stop a dropdwonlist from being autofilled. But also restyled readonly so it didn't look it. Cool idea!Bicorn
@kentcdodds: Chrome update: Google released Chrome v41 on March 19th, but I can not find any specific note in their change log. Please specify your comment: The initial question was, how to prevent Chrome from filling saved values to wrong field names. How does your example code behave? In your example I notice 3x text-input fields, without name attribute and no surrounding form tag.Melvinmelvina
In Chrome, the readonly attribute trumps the required attribute on an input which breaks client side validation.Lakia
@Clint: My code snippet above removes the readonly attribute as soon as the user enters the field (per mouse click or tab key). I guess, you refer to a field, which is auto fill protected, but not touched by the user. What is this field purpose - and does it really need to be protected? Depending on the scenario, removing all readonly attributes on submit may be an option. Can you add a more specific comment on your issue? Maybe I can help you out :)Melvinmelvina
This is not an elegant solution, using bootstrap the field is styled as a readonly input but this is not one.Christianism
@Loenix: your sample is about a different answer and uses autocomplete="off", while my solution is about the readonly attribute. Btw. I guess there is a little typo in the fiddle you listet. The event listener $(this).one("focus... should likely be $(this).on("focus.... Kind regards, dsuessMelvinmelvina
@Melvinmelvina This script apply the readonly solution on a field with autocomplete="off". It uses one jQuery method to apply event only one time, because after the first focus event, the readonly attribute is already removed (here i respect jQuery standards, we should edit the property and not the attribute). api.jquery.com/oneChristianism
If you're using JavaScript. why not just set the value to dummy and then remove the value again? Adding and removing readonly sounds like a hazardous move - what if the browser doesn't want you to focus on it?Airy
This is misleading though, as the field has a grey background indicating to the user that it is disabled (which it is) and shows the banned cursor when hovering over it. Only when the user clicks it, which they wouldn't normally do since the styles tell them not, does it actually start working. It may work, but is counter intuitive IMO and bad UX. I suppose you could add styles to address this though.Communicative
this is the only solution worked for me out of all other workarounds in the internet. this works in safari where I had problem. what a stupid bug and wat a good fix. btw I need to add onblur="this.setAttribute('readonly', true);" to make it work perfectlyPictograph
not working in Chrome 67, in Firefox 60 only on first focus, then with no readonly attribute it keeps offering stored passwords for certain userEthnocentrism
@Melvinmelvina I am still getting autocomplete box on this example jsfiddle.net/danielsuess/n0scguv6. Google Chrome Version 71.0.3578.98 (Official Build) (64-bit) , OS X Mojave.Frenchy
Chrome version 72.0.3626.121 (Official Build) (64-bit), This is the only solution that worked for me...Nb
For my purposes I needed to insure the field didn't get auto populated AFTER it lost focus. <input type="password" readonly onfocus="this.removeAttribute('readonly');" onfocusout="this.setAttribute('readonly', 'readonly');"/>Ogdoad
Apparently google is trying to make decisions for all of us here, they closed the ticket regarding autocomplete="off": bugs.chromium.org/p/chromium/issues/detail?id=468153. But there is another ticket opened for collecting valid user cases for disabling autofill, please reply this ticket to raise more awareness of this issue here: bugs.chromium.org/p/chromium/issues/detail?id=587466Cut
I prefer to use this instead: <input type="text" onfocus="this.setAttribute('type', 'password');"/>Alphaalphabet
This works, BUT now the cursor styling shows as not allowed.Pronto
@Alphaalphabet This don't work in my Chrome password field. Well i don't get the autocomplete, but it stays as a text input (no dots) and I also have to use the autocomp.. off.Rochellerochemont
S
102

If you are implementing a search box feature, try setting the type attribute to search as follows:

<input type="search" autocomplete="off" />

This is working for me on Chrome v48 and appears to be legitimate markup:

https://www.w3.org/wiki/HTML/Elements/input/search

Sensitize answered 25/2, 2016 at 22:30 Comment(9)
Yes! :) Thank you! This works in Chrome 67.0.3396.99. (I think your link should be: w3.org/wiki/HTML/Elements/input/search as of September 2018).Educational
Finally! still works Version 69.0.3497.100 (Official Build) (64-bit) This should be the real answer!Walrus
everybody is right and wrong and the same time you should write autocomplete="off" inside the tag <form autocomplete="off" > instead on input and this will stop the autofill behaviorProfiteer
Confirmed - this is the only correct answer here that doesn't break proper form structure. Works as of Dec 2018 in all current browsersUnyielding
Also works if you set autocomplete="off" on the form (to change that default form-wide) and then just need to set type="search" on the <input>Kempis
After Chrome version 72.XX, this fix does not work. Find the lastest fixe here https://mcmap.net/q/57967/-autocomplete-off-vs-falseBlameful
Thank you thank you thank you. This did it for me. We have an address form where the street input has a custom auto-complete that we implemented, but the chrome AutoFill/AutoComplete always appears on top of ours. This fix did it.Dextrosinistral
Who is looking how to hide built-in browser styling for the input type search: (SCSS): input[type='search'] { /* clears the 'X' from Internet Explorer / &::-ms-clear, &::-ms-reveal { display: none; width: 0; height: 0; } / clears the 'X' from Chrome */ &::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration { display: none; } }Shinbone
Works great, but then the password isn't hidden...Mentally
T
90

I don't know why, but this helped and worked for me.

<input type="password" name="pwd" autocomplete="new-password">

I have no idea why, but autocomplete="new-password" disables autofill. It worked in latest 49.0.2623.112 chrome version.

Tankersley answered 12/4, 2016 at 22:5 Comment(13)
Updated my chrome, and still it does work for me. 50.0.2661.87 (64bit)Tankersley
Unfortunately, when submitting the form (or when the input fields are hidden/removed), Chrome then asks to save the changed login.Schertz
Works in Version 51.0.2704.79 mJosiejosler
holy f*** why this works? is that a bug? because i tested it here and place it only in one input and worked for both input login and password, but i put it only in the passwordRandolphrandom
I have no idea. I think thats a chrome "thing" which was made by developers. Maybe i am mistaken.Tankersley
As of July 2018 - this is working... but must be named new-passwordClassicize
Similar for me. I applied it to the password field. Applying to the form or other fields didn't work for me. I'm using Chrome Version 75.0.3770.142Adherence
Only answer that still actually works at the moment.Successful
This one works for me too. All other options "off", "false", etc. not workingSmoking
Doesn't work anymore....Mentally
Aug 2022, and this was the only option that worked for me, having tried the 3 answers above.Rumney
@Rumney does it work in firefox, didnt work for meTomasatomasina
I have a form with 4 inputs, using new-password in the first works, but if I use that again in another input then none of them work! But using unique variations works - so I have new-password, old-password, and password in the first 3. I'm stuck with autocomplete on the 4th bcs I can't come up with another working variation ...Alys
D
66

Try this. I know the question is somewhat old, but this is a different approach for the problem.

I also noticed the issue comes just above the password field.

I tried both the methods like

<form autocomplete="off"> and <input autocomplete="off"> but none of them worked for me.

So I fixed it using the snippet below - just added another text field just above the password type field and made it display:none.

Something like this:

<input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;" />
<input type="password" name="password_fake" id="password_fake" value="" style="display:none;" />
<input type="password" name="password" id="password" value="" />

Hope it will help someone.

Diurnal answered 14/5, 2014 at 5:13 Comment(14)
This doesn't work well for me: chrome still autofills the password field visibly, while the username is indeed hidden.Improbity
yes its not for password its for user name if you need password too try to create a password fake field too.check my editDiurnal
This one worked for me (for now). I have found that I have used about a half dozen different hacks over time, and after a while Chrome decides it wants to defeat that hack. So a new one is needed, such as this one. In my application, I have a profile update form with email and password fields that are to be left blank unless the user wants to make changes. But when Chrome autofills, it puts the userid in the "email confirmation" field, resulting in all kinds of error conditions, that lead to further error conditions, as the user flounders about trying to do the right thing.Locarno
A quick explanation as to why this hack works (for now): Chrome sees the first type=password input and autofills it and it assumes that the field directly before this MUST be the userhame field, and autofills that field with the username. @JeffreySimon this should explain the phenomenon of userid in email confirmation field (I was seeing the same thing on my form).Framework
I suspect it won't be long before Chrome figures out how to defeat this hack. Why does Chrome try to hard to prevent a function that should be up to the developer?Locarno
@kentcdodds - not sure what you mean about no longer working. Your jsbin does not have a password field so is a different situation. I've been using this solution for years and most recently I noticed it was needed and it worked for me just last week (March 2015).Ambriz
Hooray! A solution that seems to work! I would advise giving the field the name password and having actual_password for the legitimate field, as Google now seem to be looking at the name. However, this means Chrome won't then save the password, which is the functionality I actually want. AAAAARRRRGHH!Airy
Update: This continues to work over a year since the last time I implemented it. We may have a solid winner here.Framework
wow Chrome, you surprise me, is there some bug submitted or whatever?Acetal
this doesn't work in the latest Chrome (48.0.2564.109). when the fake input is visible, it captures the autofill, but when it's hidden via display none - it doesn't. I tried to absolutely position the fake input and give it 0 width and height, also doesn't work. The only way I managed to make it work is with height of 1px.Quahog
<form autocomplete="off"> worked for me in Chrome 50somethingAmias
Using this approach I found that Firefox would still autofill the hidden fields, which would then be posted along with the rest of the form when submitting. Something that is not desirable with your credentials. Adding maxlength="0" prevents that.Brookite
So name or id attribute has to be session-unique so that autofill doesn't kick in. Alternatively leave out name/id and give autocomplete attribute a unique value (like +(new Date())). Examples here: jsfiddle.net/mfdc22pzAgglutinogen
This no longer works for me in 69.0.3497.100 (October, 2018).Protagonist
G
56

For me, simple

<form autocomplete="off" role="presentation">

Did it.

Tested on multiple versions, last try was on 56.0.2924.87

Grandparent answered 3/9, 2016 at 7:0 Comment(9)
@ArnoldRoa version added, it's been on our site since the day I've posted it and had few versions where it worked fine. which version are you using? PC/Mac?Grandparent
Not working on 57.0.2987.110. Chrome highlights it yellow and prefill the field with my saved password. But the page is a user management page, not login page.Insistence
@Dummy I tested it now on chrome latest (57) and it's still working for me. Did you do anything special with the input fields? cap you put your code somewhere I could try to reproduce?Grandparent
Working in Version 63.0.3239.132Landis
Version 64.0.3282.186 (Official Build) (64-bit) Windows. 2018-03-01 NOT WORKING for disabling autofill.Tragic
Worked Google Chrome 67.0.3396.99 (Official Build) (64-bit) (cohort: Stable)Altman
Pretty sure this removes the form / input from assistive technologies w3c.github.io/using-aria/#ariapresentationDrawbridge
this is the only working thing in chrome 88 at Mac at the moment.Hematology
Just found this July 2022 and does the trick. I made a minor tweak autocomplete="off" on the form and role="presentation" on the individual input.Moderator
L
33

You have to add this attribute :

autocomplete="new-password"

Source Link : Full Article

Lewan answered 21/10, 2016 at 14:12 Comment(4)
Do you have any sources how to figure this out?Houston
Works, but is not semantic as can be used on username and other fields.Lacey
Documentation page: developer.mozilla.org/en-US/docs/Web/Security/…Zipporah
2022, android chrome 104. still not follow the rulesBoydboyden
L
22

It is so simple and tricky :)

google chrome basically search for every first visible password element inside the <form>, <body> and <iframe> tags to enable auto refill for them, so to disable this you need to add a dummy password element as the following:

    • if your password element inside a <form> tag you need to put the dummy element as the first element in your form immediately after <form> open tag

    • if your password element not inside a <form> tag put the dummy element as the first element in your html page immediately after <body> open tag

  1. You need to hide the dummy element without using css display:none so basically use the following as a dummy password element.

    <input type="password" style="width: 0;height: 0; visibility: hidden;position:absolute;left:0;top:0;"/>
    
Locule answered 16/3, 2016 at 8:24 Comment(10)
Great work, how did you find out the algorithm of Chrome? I just found out that my old method changing the value with JS after the page has been loaded with a setTimeout timer doesn't work anymore. But this works perfect!Adler
Unfortunately, does not work for regular TextBox inputs.Exemplar
actually it is working just set the name property ;)Locule
On Chrome 58 this does not work. Use width:1px. If the password field is completely hidden, then Chrome autofills it normally. Also z-index:-999 could be useful so it does not overlap any content.Hospitium
Can't believe this worked. I added the dummy element to a random username field that is for searching other usernames and didn't have any password field near it, using the bootstrap class 'hidden', then when I loaded the page again the input was clear, but one of my other inputs called Email Address was now populated with the username. So then I had to add a dummy class before the Email Address input and that ID needed to have the words 'email' and 'address'. That solved the problem.Timmi
Works on Chrome 67.0 on angular html component <form *ngIf="!loggedIn()" #loginForm="ngForm" class="navbar-form navbar-right" (ngSubmit)="login()"><input type="password" style="width: 0;height: 0; visibility: hidden;position:absolute;left:0;top:0;"/><input type="text" #username="ngModel" placeholder="Username" class="form-control" required autocomplete="off" name="username" [(ngModel)]="model.username"><input type="password" #password="ngModel" placeholder="Password" class="form-control" required autocomplete="off" name="password" [(ngModel)]="model.password">...Luzern
Confirmed this is working Chrome: 71.0 for putting a dummy password element as the first element in your form immediately after <form> open tag - sooo happy!Din
76.0.3809.100 is leaving some random username in some email field in a vuejs site - had to enable it for all form actions due to templates - is causing other side issues now - upon removing it the username no longer appeared in the email field. strangeAsquint
Super, thank you, after searching and trying, this finally solved it!Westernmost
Thank you, only solution working for Chrome 96 (December 2021).Kenyatta
G
22

Use css text-security: disc without using type=password.

html

<input type='text' name='user' autocomplete='off' />
<input type='text' name='pass' autocomplete='off' class='secure' />

or

<form autocomplete='off'>
    <input type='text' name='user' />
    <input type='text' name='pass' class='secure' />
</form>

css

input.secure {
    text-security: disc;
    -webkit-text-security: disc;
}
Grandfatherly answered 16/1, 2018 at 19:33 Comment(4)
best approach I found so far! well, at least for Chrome 64 :/Ageless
For my purposes this is perfect, thank you! Chrome doesn't autofill or autocomplete it, doesn't offer to save it, and not only is it obscured from view but also from the clipboard - I copied what I'd typed and pasted it into notepad and just got "•••••••••••". Brilliant!Aeneas
"text-security" is not a valid css property as of october 2020Us
this is the actual true answer with no need to date-xxxx updated!Passageway
A
20

Here are my proposed solutions, since Google are insisting on overriding every work-around that people seem to make.

Option 1 - select all text on click

Set the values of the inputs to an example for your user (e.g. [email protected]), or the label of the field (e.g. Email) and add a class called focus-select to your inputs:

<input type="text" name="email" class="focus-select" value="[email protected]">
<input type="password" name="password" class="focus-select" value="password">

And here's the jQuery:

$(document).on('click', '.focus-select', function(){
  $(this).select();
});

I really can't see Chrome ever messing with values. That'd be crazy. So hopefully this is a safe solution.

Option 2 - set the email value to a space, then delete it

Assuming you have two inputs, such as email and password, set the value of the email field to " " (a space) and add the attribute/value autocomplete="off", then clear this with JavaScript. You can leave the password value empty.

If the user doesn't have JavaScript for some reason, ensure you trim their input server-side (you probably should be anyway), in case they don't delete the space.

Here's the jQuery:

$(document).ready(function() {
  setTimeout(function(){
    $('[autocomplete=off]').val('');
  }, 15);
});

I set a timeout to 15 because 5 seemed to work occasionally in my tests, so trebling this number seems like a safe bet.

Failing to set the initial value to a space results in Chrome leaving the input as yellow, as if it has auto-filled it.

Option 3 - hidden inputs

Put this at the beginning of the form:

<!-- Avoid Chrome autofill -->
<input name="email" class="hide">

CSS:

.hide{ display:none; }

Ensure you keep the HTML note so that your other developers don't delete it! Also ensure the name of the hidden input is relevant.

Airy answered 13/6, 2015 at 22:12 Comment(3)
@Vaia - have you tried navigating to another page and then pressing the back button? I get mixed results - it may need tweaking.Airy
I haven't tried option 1 if you mean that. Also I just needed to disable the autofill on an ajax-loaded modal that won't be called with the back button. But if there will be other results, I'll tell you. @AiryHouston
@Vaia I meant option 2 - please reply here if you encounter any problems. Thanks.Airy
P
20

Previously entered values cached by chrome is displayed as dropdown select list.This can be disabled by autocomplete=off , explicitly saved address in advanced settings of chrome gives autofill popup when an address field gets focus.This can be disabled by autocomplete="false".But it will allow chrome to display cached values in dropdown.

On an input html field following will switch off both.

Role="presentation" & autocomplete="off"

While selecting input fields for address autofill Chrome ignores those input fields which don't have preceding label html element.

To ensure chrome parser ignores an input field for autofill address popup a hidden button or image control can be added between label and textbox. This will break chrome parsing sequence of label -input pair creation for autofill. Checkboxes are ignored while parsing for address fields

Chrome also considers "for" attribute on label element. It can be used to break parsing sequence of chrome.

Prudence answered 23/7, 2015 at 19:20 Comment(4)
I love you. The only solution on this page that actually works.Brattice
This worked for me but only tested on Chrome.Dualpurpose
i tried autocomplete="off" alone doesnt work, after adding role="presentation" along that, makes it workCousin
This works, but it feels wrong to mess with ARIA values as a workaround (developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/…)Bonis
C
17

In some cases, the browser will keep suggesting autocompletion values even if the autocomplete attribute is set to off. This unexpected behavior can be quite puzzling for developers. The trick to really forcing the no-autocompletion is to assign a random string to the attribute, for example:

autocomplete="nope"
Celibacy answered 1/3, 2018 at 15:36 Comment(3)
RE: 'unexpected behavior' This behavior is pushed by Google who believes it knows better than developers how every single page should work. Sometimes I just want a raw password input, zero frills.Millardmillboard
this combination FINALLY worked for me: role="presentation" autocomplete="nope" tested on Chrome Version 64.0.3282.186 (Official Build) (64-bit). What a nightmare!Tragic
The random string works for chrome but not firefox. For completeness I use both "autocomplete='off-no-complete'" and set the readonly attribute with an onfocus="this.readOnly=false". My app is an enterprise appliation that users use to input thousands of addresses, so the use-case to control this is real - I can also guarantee the use of Javascript, so at least I've got that going for meMethodist
K
14
<input readonly onfocus="this.removeAttribute('readonly');" type="text">

adding readonly attribute to the tag along with the onfocus event removing it fixes the issue

Kolo answered 18/8, 2016 at 8:0 Comment(0)
A
13

I've found that adding this to a form prevents Chrome from using Autofill.

<div style="display: none;">
    <input type="text" id="PreventChromeAutocomplete" name="PreventChromeAutocomplete" autocomplete="address-level4" />
</div>

Found here. https://code.google.com/p/chromium/issues/detail?id=468153#hc41

Really disappointing that Chrome has decided that it knows better than the developer about when to Autocomplete. Has a real Microsoft feel to it.

Asteroid answered 17/11, 2015 at 20:41 Comment(1)
It's not really the fact that you say PreventChromeAutocomplete. I was able to get autocomplete to work by saying autocomplete="off" and name="somename". But this only works if you name two different inputs the same name. So in your case PreventChromeAutocomplete must have been applied to two different inputs. Very strange...Freed
M
10

In 2016 Google Chrome started ignoring autocomplete=off though it is in W3C. The answer they posted:

The tricky part here is that somewhere along the journey of the web autocomplete=off become a default for many form fields, without any real thought being given as to whether or not that was good for users. This doesn't mean there aren't very valid cases where you don't want the browser autofilling data (e.g. on CRM systems), but by and large, we see those as the minority cases. And as a result, we started ignoring autocomplete=off for Chrome Autofill data.

Which essentially says: we know better what a user wants.

They opened another bug to post valid use cases when autocomplete=off is required

I haven't seen issues connected with autocomplete throught all my B2B application but only with input of a password type.

Autofill steps in if there's any password field on the screen even a hidden one. To break this logic you can put each password field into it's own form if it doesn't break your own page logic.

<input type=name >

<form>
    <input type=password >
</form>
Mathamathe answered 31/5, 2018 at 10:6 Comment(4)
Since your answer is the most recent one, could you please add that adding autocomplete="pineapple" or some other gibberish also seems to fix the problem? At least, it did on my end!Nahamas
@DouwedeHaan this is fine until the form gets saved, then autocomplete will provide recommendations for saved 'pineapple' field. But maybe using a random hash for autocomplete value for example would get round this?Nelan
@Nelan I agree. A good example would be to use the UUID for this kind of stuff. Just make sure that the string is unique!Nahamas
revolve my problem with autocomplete="pineapple" ahah!! The dumbest workaround of my life :D Thx a lot! :DMarna
M
9

For username password combos this is an easy issue to resolve. Chrome heuristics looks for the pattern:

<input type="text">

followed by:

<input type="password">

Simply break this process by invalidating this:

<input type="text">
<input type="text" onfocus="this.type='password'">
Mairamaire answered 20/3, 2015 at 3:14 Comment(8)
Unfortunately, this applies to more than just username/password type things. Chrome will look at the placeholder text to infer what to suggest. For example: jsbin.com/jacizu/2/editHartzog
It is valid that you will still be able to fill the fields with browser suggestions as your example demonstrates, so this doesn't really address the OPs issue. This solution, just prevents the browser from "automatically" populating username and passwords combos as in the example by the top answer. This may be of use to some, but is not an end-all solution to just disabling autocomplete, that will have to come from Google.Mairamaire
Although, if you add a space in front of your placeholder text it will disable the auto-suggest based on placeholder too. Definitely a hack, although no more so than the other suggestions. jsbin.com/pujasu/1/editMairamaire
actually... it seemed to work for your example, but for some reason it's not working for me :-(Hartzog
Ha! That's why it's called a hack... Do you have an example you can share where it's not working?Mairamaire
Great this is the only one that worked on v49 for me ThanksVicissitude
This didn't work as of Version 60. Chrome actually autoselects the first password from the list (along with matching email / name) when focus occurs. :(Bonus
With chrome 69.xxx, I done that to remove stop autocomplete <input type="text"><input type="text" style="display:none"><input type="password"><input type="password" style="display:none">Dielle
M
8

Mike Nelsons provided solution did not work for me in Chrome 50.0.2661.102 m. Simply adding an input element of the same type with display:none set no longer disables the native browser auto-complete. It is now necessary to duplicate the name attribute of the input field you wish to disable auto-complete on.

Also, to avoid having the input field duplicated when they are within a form element you should place a disabled on the element which is not displayed. This will prevent that element from being submitted as part of the form action.

<input name="dpart" disabled="disabled" type="password" style="display:none;">
<input name="dpart" type="password">
<input type="submit">
Menis answered 31/5, 2016 at 15:20 Comment(3)
As for June of 2016 and Chrome 51.0.2704.106 m this is the only working solution over hereCrittenden
But will the form select the right (visible) input field you need then? Because it's the same name.Houston
@Vaia, adding the disabled attribute to the duplicate element will prevent it from being submitted.Menis
H
7

There's two pieces to this. Chrome and other browsers will remember previously entered values for field names, and provide an autocomplete list to the user based on that (notably, password type inputs are never remembered in this way, for fairly obvious reasons). You can add autocomplete="off" to prevent this on things like your email field.

However, you then have password fillers. Most browsers have their own built-in implementations and there's also many third-party utilities that provide this functionality. This, you can't stop. This is the user making their own choice to save this information to be automatically filled in later, and is completely outside the scope and sphere of influence of your application.

Humphrey answered 24/7, 2014 at 19:56 Comment(4)
The first part of this answer doesn't doesn't appear to be true anymore: Chrome BugHousecoat
I'm not sure what you're on about. That "bug" is just a placeholder for Chromium to collect people's use cases for autocomplete="off". It's possible the intent is to remove it, but that's not ever explicitly stated, and there's certainly nothing requiring that mental leap. They may just be wanting to consider alternate or better ways to treat it. Regardless, it's still part of the spec, and again, no indication that it will be leaving the spec either. And, it still works in all browsers as far as I'm aware, including Chrome.Humphrey
We have a couple of cases where autocomplete="off" is not being respected by Chrome.Housecoat
1. A couple of anecdotal cases does not amount to evidence. 2. As I said in my answer, form filling extensions and the like may not and often do not respect this. Ultimately, like all things, it's up to the client, and therefore the user. All you can do is suggest that it should not be autofilled.Humphrey
T
7

If you're having issues with keeping placeholders but disabling the chrome autofill I found this workaround.

Problem

HTML

<div class="form">
    <input type="text" placeholder="name"><br>
    <input type="text" placeholder="email"><br>
    <input type="text" placeholder="street"><br>
</div>

http://jsfiddle.net/xmbvwfs6/1/

The above example still produces the autofill problem, but if you use the required="required" and some CSS you can replicate the placeholders and Chrome won't pick up the tags.

Solution

HTML

<div class="form">
    <input type="text" required="required">
    <label>Name</label>  
    <br>
    <input type="text" required="required">
    <label>Email</label>    
    <br>
    <input type="text" required="required">
    <label>Street</label>    
    <br>
</div>

CSS

input {
    margin-bottom: 10px;
    width: 200px;
    height: 20px;
    padding: 0 10px;
    font-size: 14px;
}
input + label {
    position: relative;
    left: -216px;
    color: #999;
    font-size: 14px;
}
input:invalid + label { 
    display: inline-block; 
}
input:valid + label { 
    display: none; 
}

http://jsfiddle.net/mwshpx1o/1/

Thuggee answered 18/3, 2015 at 18:28 Comment(2)
This is the only solution that actually works. I really don't like it, but that's the crummy state we're in right now :-(Hartzog
As of 2017, this one still works fine. It just needs this script to force input focus if the user clicks on the "fake" placeholder : $("label").on("click",function(){ $(this).prev().focus(); }); Note that the label cannot be before the input... Chrome finds it! Nice creative solution! +1Cullender
G
7

I really did not like making hidden fields, I think that making it like that will get really confusing really fast.

On the input fields that you want to stop from auto complete this will work. Make the fields read only and on focus remove that attribute like this

<input readonly onfocus="this.removeAttribute('readonly');" type="text">

what this does is you first have to remove the read only attribute by selecting the field and at that time most-likely you will populated with your own user input and stooping the autofill to take over

Goble answered 18/3, 2015 at 19:24 Comment(1)
Unfortunately, this no longer works :-( jsbin.com/sobise/edit?html,css,outputHartzog
M
7

As per Chromium bug report #352347 Chrome no longer respects autocomplete="off|false|anythingelse", neither on forms nor on inputs.

The only solution that worked for me was to add a dummy password field:

<input type="password" class="hidden" />
<input type="password" />
Mickel answered 15/1, 2016 at 11:1 Comment(0)
D
7

Well since we all have this problem I invested some time to write a working jQuery extension for this issue. Google has to follow html markup, not we follow Google

(function ($) {

"use strict";

$.fn.autoCompleteFix = function(opt) {
    var ro = 'readonly', settings = $.extend({
        attribute : 'autocomplete',
        trigger : {
            disable : ["off"],
            enable : ["on"]
        },
        focus : function() {
            $(this).removeAttr(ro);
        },
        force : false
    }, opt);

    $(this).each(function(i, el) {
        el = $(el);

        if(el.is('form')) {
            var force = (-1 !== $.inArray(el.attr(settings.attribute), settings.trigger.disable))
            el.find('input').autoCompleteFix({force:force});
        } else {
            var disabled = -1 !== $.inArray(el.attr(settings.attribute), settings.trigger.disable);
            var enabled = -1 !== $.inArray(el.attr(settings.attribute), settings.trigger.enable);
            if (settings.force && !enabled || disabled)
                el.attr(ro, ro).focus(settings.focus).val("");
        }
    });
};
})(jQuery);

Just add this to a file like /js/jquery.extends.js and include it past jQuery. Apply it to each form elements on load of the document like this:

$(function() {
    $('form').autoCompleteFix();
});

jsfiddle with tests

Dustup answered 22/10, 2017 at 12:27 Comment(0)
P
7

I've finally found success using a textarea. For a password field there's an event handler that replaces each character typed with a "•".

Pentateuch answered 21/5, 2018 at 3:1 Comment(0)
C
6

Try the following jQuery code which has worked for me.

if ($.browser.webkit) {
    $('input[name="password"]').attr('autocomplete', 'off');
    $('input[name="email"]').attr('autocomplete', 'off');
}
Copartner answered 20/3, 2014 at 9:20 Comment(2)
awesome awesome solutionsIsabelleisac
You can just add autocomplete="off" to the input field instead of using jquery. And by the way, this does not work. Chrome password suggestions are still showing up.Formularize
M
6

Here's a dirty hack -

You have your element here (adding the disabled attribute):

<input type="text" name="test" id="test" disabled="disabled" />

And then at the bottom of your webpage put some JavaScript:

<script>
    setTimeout(function(){
        document.getElementById('test').removeAttribute("disabled");
        },100);
</script>
Macdonald answered 26/2, 2015 at 17:26 Comment(1)
This is a good solution, if you don't mind Javascript. I found Chrome still adds a password after clicking around the page a bit, so i re-enabled the field in an onmouseover event listener.Crimmer
C
6

By setting autocomplete to off should work here I have an example which is used by google in search page. I found this from inspect element.

enter image description here

edit: In case off isn't working then try false or nofill. In my case it is working with chrome version 48.0

Closehauled answered 17/12, 2015 at 6:24 Comment(0)
D
6

Different solution, webkit based. As mentioned already, anytime Chrome finds a password field it autocompletes the email. AFAIK, this is regardless of autocomplete = [whatever].

To circumvent this change the input type to text and apply the webkit security font in whatever form you want.

.secure-font{
-webkit-text-security:disc;}

<input type ="text" class="secure-font">

From what I can see this is at least as secure as input type=password, it's copy and paste secure. However it is vulnerable by removing the style which will remove asterisks, of course input type = password can easily be changed to input type = text in the console to reveal any autofilled passwords so it's much the same really.

Darryl answered 12/2, 2016 at 16:11 Comment(1)
Thank you! This is the only thing that works in chrome 49. Previous methods broke as chrome seems to fill all inputs with type="password" now.Deficit
S
4

I've faced same problem. And here is the solution for disable auto-fill user name & password on Chrome (just tested with Chrome only)

    <!-- Just add this hidden field before password as a charmed solution to prevent auto-fill of browser on remembered password -->
    <input type="tel" hidden />
    <input type="password" ng-minlength="8" ng-maxlength="30" ng-model="user.password" name="password" class="form-control" required placeholder="Input password">
Sciurine answered 15/9, 2015 at 8:18 Comment(1)
strange fix but somehow that's the only thing that works for me on chrome 48 :)Helyn
C
4

The most recent solution of adding autocomplete="new-password" to the password field works great for preventing Chrome from autofilling it.

However, as sibbl pointed out, this doesn't prevent Chrome from asking you to save the password after the form submission completes. As of Chrome 51.0.2704.106, I found that you can accomplish this by adding a invisible dummy password field that also has the attribute autocomplete="new-password". Note that "display:none" does not work in this case. e.g. Add something like this before the real password field:

<input type="password" autocomplete="new-password" 
style="visibility:hidden;height:0;width:1px;position:absolute;left:0;top:0">`

This only worked for me when I set the width to a non-zero value. Thanks to tibalt and fareed namrouti for the original answers.

Coverley answered 16/7, 2016 at 0:42 Comment(1)
This solution worked because it does two things: 1. prevents chrome from displaying the 'use password for' under the real password field and 2. prevents chrome from asking you if you want to save the updated password (since the hidden password field which is marked as 'new-password' has no value)Avram
E
3

The only way that works for me was:(jQuery required)

$(document).ready(function(e) {
    if ($.browser.webkit) {
        $('#input_id').val(' ').val('');
    }
});
Enamor answered 14/5, 2014 at 18:51 Comment(0)
B
3

try whit a blank space in the value :

<input type="email" name="email" value="&nbsp;">
<input type="password" name="password" value="&nbsp;">

chrome 54.0.2840.59

Badgett answered 13/10, 2016 at 23:5 Comment(1)
This inserts that nonbreaking space into the input.Defilade
J
3

My workaround since none of the above appear to work in Chrome 63 and beyond

I fixed this on my site by replacing the offending input element with

<p class="input" contenteditable="true">&nbsp;</p>

and using jQuery to populate a hidden field prior to submission.

But this is a truly awful hack made necessary by a bad decision at Chromium.

Jello answered 1/5, 2018 at 19:31 Comment(0)
K
2

Finally I think I came with a decent solution. Understanding better how the dropdown works with Chrome helped :) Basically, the dropdown will be displayed when you focus the input and when you generate a mouse down event when you are typing an entry which matches with what Chrome has in memory. Keeping that in mind, and that Chrome does it for certain inputs when they have default names like "name", "email", etc. then we just need to remove the name when the dropdown is going to be displayed and add it back after :) I wanted to use a solution which can make it work just by adding the attribute autocomplete off. I thought it made sense. This is the code:

Solution 1

jQuery('body').on('mousedown','[name="name"][autocomplete="off"], [name="email"][autocomplete="off"]',function(e){
    e.stopImmediatePropagation();
    if(typeof this.currentName =="undefined")
        this.currentName=jQuery(this).attr('name');
    jQuery(this).attr('name','');
});

jQuery('body').on('blur','[autocomplete="off"]',function(e){
    e.stopImmediatePropagation();
    jQuery(this).attr('name',this.currentName);
});

Solution 2 (My Favourite One)

The solution I described above will remove the name of the input until we remove the focus (blur), in that moment it will put the original name back. But might happen that we are interested on having access to the input through its name attribute while we are typing. Which means that we need to put the name back right after each input. This solution, basically is based on the first solution. In this case, we will add the name on key down, and put it back on keyup. I think this is more neat for compatibility with what the "autocomplete off" behaviour should be. Anyway this is the code:

jQuery('body').on('mousedown keydown','[name="name"][autocomplete="off"], [name="email"][autocomplete="off"]',function(e){
    e.stopImmediatePropagation();
    if(typeof this.currentName =="undefined")
        this.currentName=jQuery(this).attr('name');
    jQuery(this).attr('name','');
});
jQuery('body').on('blur keyup','[autocomplete="off"]',function(e){
    e.stopImmediatePropagation();
    if(typeof this.currentName !="undefined")
        jQuery(this).attr('name',this.currentName);
});

Please notice that for Solution 1 and 2, I just took the cases where the input name is "name" and "email". For any other case where this attribute makes Chrome generate the dropdown you will have to add it in the selector for the mouse down event.

Solution 3

This solution is a lot more messy. I did not realize that the behaviour we are trying to correct is just based on those inputs with a specific name like "name, email, etc". The approach of this solution was for that case that Chrome display for other names that we don't know a priori. It would be a very generic solution. I do not like as much as the other 2, basically because there could be a small flicker when we press on the delete key. I will explain that bellow.

I found out that the dropdown was appearing after a second click on the input but not on the first click when you focus the first time on the input. I bind a "mousedown" event for all this elements where the handler basically detect if it is already focused on the input and in case it detects another "mouse down", force a .blur() and then .focus() after, preventing the dropdown on the second click once it is focused. I hope, it is clear, just in case here is the code that I used:

jQuery('body').on('mousedown','[autocomplete="off"]',function(e){
    e.stopImmediatePropagation();
    if(jQuery(this).is(':focus')) {
        jQuery(this).blur();
        jQuery(this).focus();
    }
});

In the other hand, in order to prevent the dropdown while you are typing in case it matches with Chrome suggestions... This is a little bit tricky. I just decided to replace the default behaviour of an input while user types. The dropdown evaluates the input on mouse down, so I prevent the default behaviour for alphanumerics, space, etc. The only problem is with Command,Ctrl and delete. For this case I had to bind also an event on mouse up. It allows the default behaviour in the first two cases so you can make copy, and paste, or select all. In the case of the delete, I have to allow the default behaviour, but if after deleting a character the input matches with Chrome suggestions, then again it was showing the dropdown. For this case I had to use the same trick of blur and focus. The only inconvenience I found on this is that since we are cancelling the behaviour on keyup, and chrome tries to show it on keydown, there is a small flicker. Anyway, this is the best I could do. Probably it will require for filtering of characters at one point. I just added the conditions made more sense for now. This is the second part of the code:

jQuery('body').on('keydown','[autocomplete="off"]',function(e){
    e.stopImmediatePropagation();
    var ctrlKey = 17,cmKey = 91;
    var charCode = e.which || e.keyCode;

    if(charCode!=16 && this.commandDown != true && this.ctrlDown != true && ((charCode>47 && charCode<58)||(charCode>64 && charCode<91)||(charCode>96 && charCode<123)||charCode==0 || charCode==32)){ 
        e.preventDefault();
        var charStr = String.fromCharCode(charCode);
        if(!e.shiftKey)
            charStr = charStr.toLowerCase(charStr);
        $(this).val($(this).val() + charStr);
    }else{
        if (charCode == cmKey) this.commandDown = true;
        if (charCode == ctrlKey) this.ctrlDown = true;
    }
});
jQuery('body').on('keyup','[autocomplete="off"]',function(e){
    e.stopImmediatePropagation();
    var allowed=[8];//Delete
    var ctrlKey = 17,cmKey = 91;
    var charCode = e.which || e.keyCode;

    if (charCode == cmKey) {this.commandDown = false};
    if (charCode == ctrlKey) {this.ctrlDown = false};
    if(allowed.indexOf(charCode)>=0 || (this.commandDown!=false && this.ctrlDown!=false)){
        jQuery(this).blur();
        jQuery(this).focus();
}

As I said this solution is much more messy. It was the first one I used until I realized that the dropdown just appeared for certain input names.

Sorry for writing so much, I just wanted to be sure everything was clear. I hope it helps.

Kacerek answered 30/3, 2015 at 3:5 Comment(0)
A
2

I needed some extra fields for it to work properly, as chrome actually fills many fields. And I also needed to hide the fields in a more fancy way than display:none for it to actually work.

<style>.stylish { position:absolute; top:-2000px; }</style>
<input id="_____fake_email_remembered" class="stylish" tabindex="-1"  type="email" name="email_autofill"/> 
<input id="_____fake_userName_remembered" class="stylish" tabindex="-1"  type="text" name="userName_autofill"/>
<input id="_____fake_firstName_remembered" class="stylish" tabindex="-1"   type="text" name="firstName_autofill"/>
<input id="_____fake_lastName_remembered" class="stylish" tabindex="-1"   type="text" name="lastName_autofill"/>
<input id="_____fake_phone_remembered" class="stylish"  tabindex="-1"  type="text" name="phone_autofill"/>
<input id="_____fake_address_remembered" class="stylish"  tabindex="-1"   type="text" name="address_autofill"/>
<input id="_____fake_password_remembered" class="stylish"  tabindex="-1"   type="password" name="password_autofill"/>
<input id="_____fake_password_remembered2" class="stylish"  tabindex="-1"   type="password" name="passwordRepeated_autofill"/>
Apex answered 7/12, 2015 at 11:30 Comment(1)
This is something that actually worked for me after other attempts. I am using Chrome 50.Marcoux
M
2

Instead of "this is what worked for me" answers and other answers that look like complete hacks... This is currently how chrome (and the latest spec) will handle the autocomplete attributes on your input elements:

https://developers.google.com/web/fundamentals/design-and-ui/input/forms/label-and-name-inputs?hl=en

TLDR: Add autocomplete='<value>' on your inputs, where <value> should be any string that defines what the field is for. This works similarly to the name attribute. Use the suggested values on the link above where possible.

Also, remove the autocomplete attribute from your form

Michelemichelina answered 8/2, 2016 at 2:36 Comment(1)
This does not address the issue being discussed. It is about how to STOP Chrome from autofilling. Not "how to create forms properly." Either that or your TLDR doesn't fully following through on what you're addressing or the outcomes.Deloresdeloria
C
2

My solution depends on three things thing:

  1. keydown event
  2. masking the field name
  3. blanking the fields values on submit

First of all, we need to prevent autocomplete of both username and password, so, initially we will set two flags, i -> username and j -> passowrd with true value, so without any keydown to the fields both i and j will be true.

In may case the field masking is occured at the server side, by passing random string, it could be made easily made using client side too.

This is the code:

$(document).ready(function(){
   i= true; //username flag
   j= true; // password flag
   $("#username{{$rand}}").keydown(function(e){
          // {{$rand}} is server side value passed in blade view
          // keyboard buttons are clicked in the field
            i = false;       
    });
   $("#passowrd{{$rand}}").keydown(function(e){
          // {{$rand}} is server side value passed in blade view
          // keyboard buttons are clicked in the field
            j = false;       
    });
    // Now we will use change event,
   $("#username{{$rand}}").change(function(){
    if($(this).val() != ''){ //the field has value
        if(i){ // there is no keyboard buttons clicked over it
            $(this).val(''); // blank the field value
        }

    }
})
$("#password{{$rand}}").change(function(){
    if($(this).val() != ''){ // the same as username but using flag j
        if(j){
            $(this).val('');
        }

    }
})

   $("#sForm").submit(function(e){ // the id of my form
      $("#password-s").val($("#password{{$rand}}").val());
        $("#username-s").val($("#username{{$rand}}").val());
        // Here the server will deal with fields names `password` and `username` of the hidden fields
       $("#username{{$rand}}").val('');
        $("#password{{$rand}}").val(''); 

 })
})

Here are the HTML:

<form class="form-horizontal" autocomplete="off" role="form" id="sForm" method="POST" action="https://example.com/login">

                        <input type="hidden" name="password" id="password-s">
                        <input type="hidden" name="username" id="username-s">

                            <label for="usernameTDU3m4d3I5" class="col-md-3 control-label" style="white-space: nowrap">Username</label>

                                <input id="usernameTDU3m4d3I5" placeholder="Username" autocomplete="off" style="border-bottom-left-radius: 10px; border-top-right-radius: 10px; font-family: fixed; font-size: x-large;" type="text" class="form-control" name="usernameTDU3m4d3I5" value="" required="required" autofocus="">                                

                            <label for="passwordTDU3m4d3I5" class="col-md-3 control-label" style="white-space: nowrap">Password</label>
                                <input id="passwordTDU3m4d3I5" placeholder="Password" autocomplete="off" type="password" class="form-control" name="pa-TDU3m4d3I5" required="">


                                <button type="submit" class="btn btn-success">
                                    <i class="fox-login" style="text-shadow: 0px 1px 0px #000"></i><strong>Login</strong>&nbsp;&nbsp;
                                </button>

                                </form>

The above solution, indeed, will not eliminate or prevent the autocomplete of the username and password, but it make that autocomplete useless. i.e without hitting keyboard button on the field, the field value will be blank before submit, so the user will be asked to enter them.

Update

We can, also, use click event to prevent autocomplete from users list appeared under the field like the following:

 $("#username{{$rand}}").click(function(){

            $(this).val('');
            i = true;

})
$("#password{{$rand}}").click(function(){

            $(this).val('');
            j = true;

})

Limitations:

This solution may not work as expected in touch screen devices.

Final Update

I have done the following clean implementation like the following:

preventAutoComplete = true; // modifier to allow or disallow autocomplete
trackInputs = {password:"0", username:"0"}; //Password and username fields ids as object's property, and "0" as its their values
// Prevent autocomplete
    if(preventAutoComplete){
        $("input").change(function(e){ // Change event is fired as autocomplete occurred at the input field 
            trackId = $(this).attr('id'); //get the input field id to access the trackInputs object            
            if (trackInputs[trackId] == '0' || trackInputs[trackId] != $(this).val()){ //trackInputs property value not changed or the prperty value ever it it is not equals the input field value
                $(this).val(''); // empty the field
            }
        });
        $("input").keyup(function(e){
            trackId = $(this).attr('id');
            trackInputs[trackId] = $(this).val(); //Update trackInputs property with the value of the field with each keyup.
        });
    } 
Cia answered 20/5, 2018 at 19:10 Comment(0)
F
1

Also have to set the value to empty (value="") besides autocomplete="off" to make it work.

Firing answered 20/9, 2014 at 16:21 Comment(0)
K
1

Like Dvd Franco said, for me only puting automplete='off' in all fields it worked. So I put this jquery rules in $(document).ready(); function on my main .js file

$('form.no_autofill').attr('autocomplete','off');
$('.no_autofill input').attr('autocomplete','off');
Kinky answered 3/8, 2015 at 16:50 Comment(0)
E
1

So apparently the best fixes/hacks for this are now no longer working, again. Version of Chrome I use is Version 49.0.2623.110 m and my account creation forms now show a saved username and password that have nothing to do with the form. Thanks Chrome! Other hacks seemed horrible, but this hack is less horrible...

Why we need these hacks working is because these forms are generally to be account creation forms i.e. not a login forms which should be allowed to fill in password. Account creation forms you don't want the hassle of deleting username and passwords. Logically that means the password field will never be populated on render. So I use a textbox instead along with a bit of javascript.

<input type="text" id="password" name="password" />

<script>
    setTimeout(function() {
        $("#password").prop("type", "password");
    }, 100); 
    // time out required to make sure it is not set as a password field before Google fills it in. You may need to adjust this timeout depending on your page load times.
</script>

I find this acceptable as a user won't get to a password field within the short period of time, and posting back to the server makes no difference if the field is a password field as it is sent back plain text anyway.

Caveat: If, like me, you use the same creation form as an update form things might get tricky. I use mvc.asp c# and when I use @Html.PasswordFor() the password is not added to the input box. This is a good thing. I have coded around this. But using @Html.TextBoxFor() and the password will be added to the input box, and then hidden as a password. However as my passwords are hashed up, the password in the input box is the hashed up password and should never be posted back to the server - accidentally saving a hashed up hashed password would be a pain for someone trying to log in. Basically... remember to set the password to an empty string before the input box is rendered if using this method.

Equilibrium answered 29/3, 2016 at 11:42 Comment(1)
Works the best for me. Thanks for that.Hardin
C
1

On Chromium 53.0.2785.92 (64-bit) the following worked

<div style="visibility:hidden">
    <input type="text" name="fake_username_remembered">
    <input type="password" name="fake_password_remembered">
</div>

display:none doesn't work

Cyme answered 6/9, 2016 at 9:20 Comment(0)
Q
1

Boom, Google Chrome and anyone else try defeat this then.

I was able to get this implemented today 7th September 2017, but using a FormCollection of random strings that generated in my MVC View.

I would first get a new random key in my index controller of my login page , encrypt and create a new totally unique random string (i actually used a 256 bit cypher to perform this, and a unique cypher and authentication key), i then append plain text 'Username' and 'Password' on the end of each string to later help me identify from the repsonding view controller the username and password. You could also change that plain string to anything as long as you know the pattern and it's unique.

In my view, I then used these variables appropriately and then in the responding controller - searched through a FormCollection and found my matching variables - and then used the Key-Value of that item as the corresponding Username and Password to process appropriately.

The other issue i had which i think is sneaky of Chrome, is that any

Any thoughts ?

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

<input type="text" name="@Model.UsernameRandomNameString" />
<input style="font-family: 'password'" type="text" name="@Model.PasswordRandomNameString" />

LogOnModel model = new LogOnModel()
            {
                UsernameRandomNameString = Cryptography.SimpleEncrypt("Username", UniqueGeneratorKey, UniqueGeneratorKey) + "Username",
                PasswordRandomNameString = Cryptography.SimpleEncrypt("Password", UniqueGeneratorKey, UniqueGeneratorKey) + "Password",
            };

I think it a hell of a workaround, but hey it works, and i think it could also be future proof unless google determines the URL of the page has key words in it, then appropriately just adds its stupid extensions on top on any input field - but that's a little drastic.

Quacksalver answered 7/9, 2017 at 17:17 Comment(0)
B
1

In case display: none doesn't work this is also possible and it seems to be working (Chrome v60.0.3112.113):

.hidden-fields {
    opacity: 0;
    float: left;
    height: 0px;
    width: 0px;
}

<input type="text" name="username" class="hidden-fields"> 
<input type="password" name="password" class="hidden-fields">

<your actual login fields></your actual login fields>
Betroth answered 13/9, 2017 at 19:5 Comment(1)
In my case I need only , tested Chrome v63 <input type="password" name="password" class="hidden-fields">Fenella
B
1

Pure HTML solution:

(No javascript needed, no css needed and no hidden inputs needed)

<form autoComplete="new-password" ... >
        <input name="myInput" type="text" autoComplete="off" id="myInput" placeholder="Search field" />
</form>

Notes:

  • form does not necessarily need to be the direct parent of the input element
  • input needs a name attribute
Barchan answered 29/11, 2017 at 16:54 Comment(2)
It doesn't work. I'm trying with Chrome 67. Nothing. I still need a fake input with display: none! Very crazy!Hunnicutt
As simple as putting your input into a form.Intercede
P
1

For Angular users :

Since the autocomplete = 'off' ignore by new chrome versions, chrome developer suggests autocomplete= 'false | random-string', so the google chrome/modern browsers have 2 type of users helpers -

  1. autocomplete='off' (which prevents last cached suggestions).
  2. autocomplete = 'false | random-string' (which prevents autofill setting, since the 'random-string' is not known by the browser).

so what to do, in case of disabling both the annoying suggestions? Here is the trick:-

  1. add autocomplete = 'off' in every input fields. (or simple Jquery).

Example : $("input").attr('autocomplete', 'off');

  1. Remove the <form name='form-name'> tag from HTML code and add ng-form = 'form-name' in your <div> container. Adding ng-form="form-name" will also retain all your validations.
Precursor answered 23/4, 2018 at 15:17 Comment(0)
D
1

The autocomplete feature has successfully disabled via this trick. It Works!

[HTML]

<div id="login_screen" style="min-height: 45px;">
   <input id="password_1" type="text" name="password">
</div>

[JQuery]

$("#login_screen").on('keyup keydown mousedown', '#password_1', function (e) {
    let elem = $(this);

    if (elem.val().length > 0 && elem.attr("type") === "text") {
        elem.attr("type", "password");
    } else {
        setTimeout(function () {
            if (elem.val().length === 0) {
                elem.attr("type", "text");
                elem.hide();
                setTimeout(function () {
                    elem.show().focus();
                }, 1);
            }
        }, 1);
    }

    if (elem.val() === "" && e.type === "mousedown") {
        elem.hide();
        setTimeout(function () {
            elem.show().focus();
        }, 1);
    }

});
Dallasdalli answered 8/5, 2018 at 16:23 Comment(0)
A
0

I was having this problem with a "sign in now or register" modal window, and was a problem if the user had saved their credentials to the browser. Both the sign in and register fields were populated, so I was able to clear them with the following angular js directive:

(function () {
    "use strict";

    var directive = function ($timeout) {
        return {
            restrict: "A",
            link: function (scope, element, attrs) {
                $timeout(function () {
                    element.val(" ");
                    $timeout(function () {
                        element.val("");
                    });
                });
            }
        };
    };

    angular.module("app.directives").directive("autofillClear", ["$timeout", directive]);
}());

It's basically the same as some of the previous answers that would use jquery, but done in an angular way.

Alansen answered 2/6, 2015 at 7:15 Comment(1)
It worked with little modification, $timeout(function() { element.val("") }, 300)Adapa
G
0

I know this is not exactly relevant but here is what i did. The auto filled fields raise a 'change' event but only if you bind it to them as early as possible.

so i put this inside the head section.

  $(document).ready(function(){
            $('input').on('change',function(){$(this).val('')})
     }); 

and it worked for me.

Grous answered 15/7, 2015 at 8:58 Comment(0)
M
0

Enter a value of ' ' (a blank space) for the username field.

<input type = 'text' value = ' ' name = 'username' />

If you're ever populating the username with a user-entered value, code to enter a ' ' if there's no user-entered value.

Edit: I also had to change 'username' fields to have a name of something else than 'username', e.g. 'nameofuser'

Moth answered 10/9, 2015 at 14:8 Comment(0)
B
0

My hack — tested in Chrome 48:

Since Chrome tries to find out the type of field it is by looking at stuff like id or name attributes of the <input>, but also at associated <label> content, you just have to find meaningless names for these.

For the id and name, it's easy to choose something else that is not listed here.

For the label, I inserted an invisible <span> in the middle, e.g. for a city (it's messing with my Places autocomplete):

<span>Ci<span style="display:none">*</span>ty</span>

Full working example:

<!DOCTYPE html>
<html>
  <body>
    <form method="post" action="/register">
      <div>
        <label for="name">Name</label>
        <input id="name" type="text" name="name" />
      </div>
      <div>
        <label for="email">Email</label>
        <input id="email" type="text" name="email" />
      </div>
      <div>
        <label for="id1">City</label>
        <input id="id1" type="text" name="id1" /> <-- STILL ON :(
      </div>
      <div>
        <label for="id2">Ci<span style="display:none">*</span>ty</label>
        <input id="id2" type="text" name="id2" /> <-- NOW OFF :)
      </div>
    </form>
  </body>
</html>
Bendicta answered 10/2, 2016 at 0:22 Comment(0)
M
0

Unfortunately none of the solutions seem to work. I was able to blank out email (username) using

                    <!-- fake fields are a workaround for chrome autofill getting the wrong fields -->
                    <input style="display:none" type="text" name="fakeusernameremembered"/>
                    <input style="display:none" type="password" name="fakepasswordremembered"/>

technique, but password still populates.

Mariannemariano answered 12/2, 2016 at 20:28 Comment(0)
M
0

The method of hiding it by adding "display: none;" to the input didn’t work for me if the form is generated through javascript.

So instead I made them invisible by placing them out of sight:

<input style="width:0;height:0;opacity:0;position:absolute;left:-10000px;overflow:hidden;" type="text" name="fakeusernameremembered"/>
<input style="width:0;height:0;opacity:0;position:absolute;left:-10000px;overflow:hidden;" type="password" name="fakepasswordremembered"/>
Mcreynolds answered 6/5, 2016 at 12:55 Comment(0)
O
0

Since display none doesn't seem to work anymore add the

<input type="text" name="fakeusernameremembered"/>
<input type="password" name="fakepasswordremembered"/>

inside a div with overflow hidden, max-width & max-height 0px

So it becomes something like:

<div style="overflow: hidden; max-width: 0px; max-height: 0px;">
    <input type="text" name="fakeusernameremembered"/>
    <input type="password" name="fakepasswordremembered"/>
</div>
Orlon answered 5/12, 2016 at 15:18 Comment(2)
This does not work, both inputs, fake and new are yellow-autocompleted :(Corniculate
still works for me though, can you give some more details about what you are doing? Also: did you put the div with hidden inputs before the visible ones?Orlon
B
0

Jan 20 chrome update

None of the solutions above, including adding fake fields or setting autocomplete=new-password works. Yes with these chrome will not autocomplete but when you enter the password field it will suggest the password again.

I found that if you remove the password field and then add it again without an id then chrome does not autofill it and does not suggest the password on entry.

Use a class to get get the password value instead of an id.

For firefox there is still a need to add a dummy element.

This solution also allows allowing/forbidding autocomplete based on a flag:

html:

<!-- form is initially hidden, password field has a dummy id and a class 'id' -->
<form id="loginForm" style="display:none;">
   <span>email:</span><input type="text" placeholder="Email" id="loginEmailInputID"/>
   <span>Password:</span><input class="loginPasswordInput" type="password" placeholder="Password" id="justForAutocomplete"/>
</form>

page load:

function hideAutoComplete(formId) {
    let passwordElem=$('#'+formId+' input:password'), prev=passwordElem.prev();
    passwordElem.remove();
    prev.after($('<input type="password" style="display:none">'), passwordElem.clone().val('').removeAttr('id'));
}

if (!allowAutoComplete) hideAutoComplete('loginForm');
$('#loginForm').show();

when you need the password:

$('.loginPasswordInput').val();
Burse answered 20/1, 2017 at 4:28 Comment(0)
R
0

If you are using Symfony forms, autocomplete=off will not work IF the attribute is applied from the twig template rather than using FormBuilder.

Use this:

....
->add('field-name', TextType::class, array(
  'attr' => array(
      'autocomplete' => 'off'
  )
)
....

Rather than:

....
{{ form_widget(form.field-name, {'attr': {'autocomplete':'off'}})
....
Relator answered 12/2, 2017 at 11:2 Comment(0)
E
0

None of the other solutions to these question worked for me.

The only think that worked is this one:

It removes "name" and "id" attributes from elements and assigns them back after 1ms. Put this in document get ready.

$(document).ready(function() {
    $('form[autocomplete="off"] input, input[autocomplete="off"]').each(function () {

                var input = this;
                var name = $(input).attr('name');
                var id = $(input).attr('id');

                $(input).removeAttr('name');
                $(input).removeAttr('id');

                setTimeout(function () {
                    $(input).attr('name', name);
                    $(input).attr('id', id);
                }, 1);
            });
});
Enzyme answered 5/7, 2017 at 12:11 Comment(0)
J
0

Answer of Jobin Jose gave me a start. Here is what works for me:

<input type="password" name="password" id="password_fake" style="display:none;" />
<input type="password" name="password"/>

Be sure to not have autocomplete="off", which spoils the solution.

Juliajulian answered 25/9, 2017 at 9:55 Comment(1)
This works for me as of 1.13.2018 Version 63.0.3239.132 (Official Build) (64-bit)Iives
A
0

None of the solutions worked for me. Finally, after pulling my hair out for many hours I came up with this solution for ReactJS.

Tested on FireFox 54.0.1, Chrome 61.0.3163.100, Mac OS 10.13

I keep the type="text" and change it to relevant type on onChange event.

ex: HTML:

<input type="text" onChange={this.setAttributes} placeholder="Email" />

JS:

setAttr2: function(e){
    var value = e.target.value;
    if(value.length){
      e.target.setAttribute('type', 'email')
    } else {
      e.target.setAttribute('type', 'text')
    }
  }
Archivist answered 2/10, 2017 at 12:7 Comment(0)
S
0

My problem was that Chrome would autofill postal code, over the Bootstrap autocomplete interface as I was auto suggesting possible values from my database.

Things I had to do:

  • Change input field's id property to something other than "postcode"
  • Change input field's autocomplete value to false
  • After calling $('#postcode_field').autocomplete(...) I had to reset the autocomplete property with $('#postcode_field').prop('autocomplete', 'false'); because Boostrap's autocomplete plugin changes it to off automatically.
Surreptitious answered 20/12, 2017 at 14:10 Comment(0)
P
0

I've tried all the mentioned advises but none of them worked. I'm using a google places autocomplete on the specifik input, and it is quite ugly if there is a google chrome autofill above the google places autocomplete list. Even setting autocomplete="anything" is useless because the autocomplete plugin itself setf this attr to "off" and it is totally ignored by chrome.

so my sollution is:

var fixAutocomplete = window.setInterval(function(){
    if ($('#myinput').attr('autocomplete') === 'false') {
        window.clearInterval(fixAutocomplete);  
    }

    $('#myinput').attr('autocomplete', 'false');
}, 500);
Pierpont answered 24/12, 2017 at 19:16 Comment(0)
C
0

What I have done it to change the input type="text" to a multi line input ie.

 overflow-x:hidden;
 overflow-y:hidden;
 vertical-align:middle;
 resize: none;

A quick explanation of the code: The overflow-x and -y hidden wil disable the scroll buttons on the right of the textarea box. The vertial algin will align the lable vertical middle with the text area and the resize: none will disable the resize grabber at the bottom right of the textarea.

In essance it means that your textarea will appear like a textbox, but with chrome autofill off.

Crenel answered 21/3, 2018 at 9:24 Comment(3)
While this code snippet may be the solution, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.Nucleon
The first colon in the 2nd line is probably a typo.Flighty
I agree with L. Guthardt. Please provide a complete example that showcases your solution, preferably on jsfiddle, jsbin, codepen or similar demo website.Borstal
P
-1

With chrome, if you surround an input with a label and within the label, put the words street, address or both, it will ignore any attempt at disabling autofill.

<label for="searchAddress" class="control-label"> Street Address <input type="text" class="form-control" name="searchAddress></label>

Chrome detects keywords within the label to figure out the input type. It likely does this with other key words as well.

Pipestone answered 25/2, 2016 at 3:34 Comment(0)
M
-1

Thought i'd post my fix. Found that you can't use display:none so i came up with a quick and dirty solution to just make the fake input small and move it out of sight. So far so good until they break it again.

                    <input id="FakePassword" type="password" style="float:left;position:relative;height:0;width:0;top:-1000px;left:-1000px;" />
Manus answered 7/4, 2016 at 17:53 Comment(0)
H
-1

I finally solved this by putting in a non duplicate variable in the input field - i used php time() like this:

<input type="text" name="town['.time().']" >

This was interfering mostly n android. All i did on the server side was to do a foreach loop on the input name - the issue is if chrome recognizes the name attribute it WILL auto populate.

Nothing else even worked for me.

Haemostat answered 7/4, 2017 at 0:54 Comment(2)
Checking the DOM over a billion times for each received request? No comments.Defilade
actually this works with PHP: ``` <input type="text" name="whatever" autocomplete="off_<?php echo time() ?>"> ``` This disabled the autofill on Chrome at 30-Nov-2018Scarron
S
-2

My Solution:

$(function(){
    $("form[autocomplete=off]").find('input').attr('autocomplete', 'false');
});

It sets the attribute 'autocomplete="false"' on all input fields in the forms that have 'autocomplete="off"'.

This works on chrome, firefox and safari.

Seeto answered 27/9, 2015 at 20:14 Comment(0)
D
-2

last time I checked Google updated their autofill in JAN 2017, the solution that worked for me was adding another input and hiding it after it has been populated.

 <input type="text" id="phone_number" name="phone_number" value="">
 <input type="text" id="dummy_autocomplete">


<script type="text/javascript">
        $('#dummy_autocomplete').hide();
</script>
Delicacy answered 13/1, 2017 at 12:43 Comment(0)
F
-7

This is the most recent solution that I have used.

$('#email').prop('autocomplete', true);
Felicle answered 3/5, 2018 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.