619

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?

George Kagan
  • 5,207
  • 8
  • 44
  • 49
templaedhel
  • 6,317
  • 3
  • 11
  • 5
  • 1
    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. – Jukka K. Korpela Apr 01 '13 at 06:43
  • 3
    @JukkaK.Korpela Autocomplete looks like [this](http://f.cl.ly/items/0V2A200L3P071i0D3I0Q/Screen%20Shot%202013-04-01%20at%2012.40.33%20AM.png) where it suggests values as you type. The auto populate looks like [this](http://imgsrv.worldstart.com/images/ct-images/2011/02/clark_chrome_autofill_4.jpg) 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. – templaedhel Apr 02 '13 at 16:26
  • 1
    possible duplicate of [Google Chrome form autofill and its yellow background](http://stackoverflow.com/questions/2920306/google-chrome-form-autofill-and-its-yellow-background) – Jukka K. Korpela Apr 02 '13 at 16:48
  • 6
    It's not a duplicate. This one handles disabling the autofill, that one handles styling the autofill color ... – Nicu Surdu May 08 '13 at 09:04
  • 17
    autocomplete="false" instead of autocomplete="off" as per Kaszoni Ferencz answer, get voting for it people. – roughcoder Apr 21 '15 at 10:20
  • possible duplicate of [How do you disable browser Autocomplete on web form field / input tag?](http://stackoverflow.com/questions/2530/how-do-you-disable-browser-autocomplete-on-web-form-field-input-tag) – Brad Werth Apr 28 '15 at 18:41
  • 7
    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. – mindplay.dk Jul 28 '15 at 13:06
  • I agree with @mindplay.dk. Read more about the controversy at https://groups.google.com/a/chromium.org/forum/#!msg/security-dev/wYGThW5WRrE/qiWrKwJ79S4J 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. – Fuhrmanator Sep 20 '15 at 22:16
  • 1
    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. – Fuhrmanator Sep 20 '15 at 22:17
  • 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. https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion – curiouser Jan 29 '16 at 17:00
  • autocomplete="off" works.... For me: – pim Mar 27 '16 at 21:29
  • 21
    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. – Mike K Apr 28 '16 at 22:00
  • 1
    Note that if your
    tag has autocomplete="on", then it will override autocomplete="false" for individual form elements
    – groovenectar Jul 06 '16 at 22:06
  • 8
    @mindplay.dk - 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. – PoloHoleSet Aug 02 '16 at 18:56
  • By having placeholder = " " resolved issue for me in chrome. In html you can do this: ``. 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. – Faran Shabbir Apr 21 '18 at 12:23
  • 2
    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](https://bugs.chromium.org/p/chromium/issues/detail?id=352347). – Jefrey Sobreira Santos May 12 '18 at 00:15
  • 1
    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. – Michael Berry Jul 20 '18 at 09:27

68 Answers68

1062

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


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.

GG.
  • 17,726
  • 11
  • 69
  • 117
tibalt
  • 12,677
  • 1
  • 26
  • 22
  • 141
    'new-password' worked for me after trying 'off' and 'false' – Kevin Jul 31 '15 at 16:44
  • 3
    Worked on Chrome V 44, see documentation here: https://developers.google.com/web/fundamentals/input/form/label-and-name-inputs?hl=en – Anas Aug 06 '15 at 05:46
  • 28
    This is the only working fix now. False, and off, do not work anymore. Should be the correct answer now. – David Aug 07 '15 at 02:02
  • 3
    Works for Version 44.0.2403.130 m - only thing that worked for me! – Rob Scott Aug 07 '15 at 17:12
  • 2
    This does not work for me, chrome still auto fills lastname and password for new accounts. chrome is ignoring autocomplete attribute. – John Little Aug 31 '15 at 08:42
  • 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 `
    ` element.
    – www139 Jan 01 '16 at 17:41
  • 1
    Works 100%. Simple and effective. Thank you so much, tested on 50.0.2661.94 m – MrFabio May 05 '16 at 08:58
  • 1
    Unfortunately Chrome then asks the user to save the changed password when the form is submitted/hidden. – sibbl Jun 09 '16 at 08:29
  • Works in Version 51.0.2704.79 m – Geoffrey Hale Jun 14 '16 at 22:37
  • 1
    Not working for me (on mobile, non-password field). Shows up as `autocomplete="off"` in the HTML, which of course doesn't work. – dlsso Jul 21 '16 at 01:09
  • Worked perfectly on Chrome 51.0.2704.103 m (64-bit) – Ariel Jul 23 '16 at 00:47
  • 2
    It prevent autofill, but how to disable autocomplete for password field – gozizibj Aug 02 '16 at 07:39
  • @Daniel, works in Version 52.0.2743.116 (64-bit) on macOS (10.12 Beta (16A304a)) - At least for me. – Eax Sep 06 '16 at 11:38
  • 2
    After 2 hours trying other suggestions this works! Chrome 54.0.2840.71 – Deminetix Nov 16 '16 at 02:29
  • 6
    The reason this works is because the chrome team are trying to create recommended autocomplete values, as shown @ https://developers.google.com/web/fundamentals/design-and-ui/input/forms/#recommended_input_name_and_autocomplete_attribute_values 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 suggestions – Deminetix Nov 16 '16 at 02:32
  • Setting `autocomplete="new-password"` is the only thing that worked for me. – Kevin Haag May 26 '17 at 00:44
  • This answer works for me **** 6/5/2017 *** Version 58.0.3029.110 (64-bit) –  Jun 05 '17 at 18:58
  • 2
    This did not work as of 8.30.2017 Version 60.0.3112.113 (Official Build) (64-bit) – Mike Purcell Aug 30 '17 at 15:31
  • For react: `autoComplete="new-password"` – Oliver Lloyd Oct 09 '17 at 18:13
  • 31
    Not working as of 1.13.2018 Version 63.0.3239.132 (Official Build) (64-bit) – PellucidWombat Jan 13 '18 at 17:54
  • is working with react 16, Chrome version 64: 'new-password' , I' don't know if work without react – stackdave Mar 01 '18 at 09:16
  • works like a charm Version 64.0.3282.186 (Official Build) (64-bit) – Johann Combrink Mar 05 '18 at 12:16
  • worked in Vue until I updated and memorised the password on the login view again now it's started autofilling again. – 9swampy May 07 '18 at 18:10
  • For my text input not used for password works this: – Ales May 13 '18 at 10:53
  • 1
    Does not work for me with React and Meteor. Chrome Version 66.0.3359.139 – JaySon May 18 '18 at 11:56
  • 1
    I copied autocomplete="off" from google map, and it works on chrome version 66. – hungmi May 28 '18 at 13:01
  • 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. – png Aug 10 '18 at 17:50
  • 3
    autocomplete="off" is working again now as of Chrome Version 68.0.3440.106 (Official Build) (64-bit) – mothmonsterman Aug 30 '18 at 17:38
  • 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: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill – redfox05 Dec 05 '18 at 21:23
  • 1
    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: https://cloudfour.com/thinks/autofill-what-web-devs-should-know-but-dont/#yay-for-standards-were-done-right – redfox05 Dec 05 '18 at 21:32
  • 2
    Doesn't work anymore. A working 'solution' (for me) is supplied here: https://stackoverflow.com/questions/12374442/chrome-ignores-autocomplete-off/32578659#32578659 – GerardV Dec 31 '18 at 13:09
  • 1
    Original bug has been marked as won't fix. Someone has reopened here https://bugs.chromium.org/p/chromium/issues/detail?id=914451 please star it if you think this should be fixed. – Richard Garside Jan 15 '19 at 10:29
  • 1
    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. – Rob Jan 29 '19 at 03:27
  • 1
    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('​'); In HTML you can simply put a '​' between parts of your label like 'nu​mber' or 'ca​rd'. – westor Mar 06 '19 at 10:04
  • This is the only solution that worked for me. Works in newer versions of chrome too – Prabo Mar 14 '19 at 14:16
  • 70
    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. – Eddy Howard Mar 18 '19 at 21:20
  • give name as which field auto populating. .hide-input{ width: 0; height: 0; border: none; position: absolute; } – vijay kumar Mar 28 '19 at 07:51
  • Here's where the Chrome autofill source code is. https://chromium.googlesource.com/chromium/src.git/+/refs/heads/master/chrome/browser/autofill/ 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. – jinglesthula May 07 '19 at 15:25
  • 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: https://www.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 Chrome – mkbctrl Jun 12 '19 at 10:17
  • Worked for me Chrome Version 75.0.3770.142 – Praveen Dabral Aug 12 '19 at 10:22
  • 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! – Julesezaar Sep 19 '19 at 12:43
  • 1
    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. – Nucleon Nov 15 '19 at 02:59
  • 1
    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: `` JS with jquery: `$(function () { $('#myPassword').attr('type', 'password')});` – mendez7 Jan 07 '20 at 09:26
  • The correct answer is now autocomplete="disabled" off and false values do not work anymore – Codezilla Feb 03 '20 at 20:43
  • 2
    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. – 3Dom Mar 14 '20 at 06:43
  • 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. – 3Dom Mar 15 '20 at 00:17
  • 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 password – Nithin Baby Apr 23 '20 at 10:13
  • 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. – Matt Smith May 12 '20 at 12:49
  • 3
    `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. – Dino Jun 15 '20 at 22:08
  • `autocomplete="new-password"` works as per: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#Browser_compatibility – virtualmic Jul 23 '20 at 06:12
  • Nothing really works here with Chrome. I'm using plain-text boxes now. – Chuck Oct 07 '20 at 05:49
  • Only `autocomplete="off"` is working for me with Chrome v.85/85 on MacOS 10.15. – KFoobar Oct 20 '20 at 06:51
  • This is the only way I could make it work in 2020: https://stackoverflow.com/questions/60689757/how-to-disable-chrome-autofill-after-2020/64471795#64471795 – Thales Kenne Oct 24 '20 at 01:38
  • 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. – Craig Howell Oct 30 '20 at 01:20
  • 3
    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... – Chaoste Oct 30 '20 at 16:22
  • 2
    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 help – Igor Bukin Nov 09 '20 at 14:42
  • 4
    None of the answers work for me. What in the world disables Chrome autofill? – Corey Dec 09 '20 at 22:13
  • autocomplete="chrome-off" is working on my chrome on last osx. We need a consistent solution from google.. – Davide C Dec 15 '20 at 12:23
  • My experience involved erroneous autofilling on a lone element, which is valid. When that input element was provided a parent
    then Chrome 87 stopped erroneously autofilling an input element that clearly had nothing to do with the autofill chrome was using.
    – Rich Andrews Jan 12 '21 at 22:42
  • 1
    Not working on latest Brave or Edge on Windows. Only thing that works is `autocomplete=""` on *every* affected field. – Rei Miyasaka Mar 08 '21 at 21:09
  • 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. – Ruben Mar 16 '21 at 14:32
  • 1
    I'm trying in Chrome 89.0.4389.90 on macOS and it's not working :/ – Gavin Mar 25 '21 at 15:07
  • 1
    So on Win 10 Chrome 89 my only solace came from prepending the autocomplete property with "new-", eg. `` – Latchy Apr 07 '21 at 14:36
  • 1
    This isn't working in my newest version of Chrome now. – Jaden Baptista Apr 19 '21 at 22:21
  • As of 2021: this has worked for me, `autocomplete="chrome-off"` – tmarois Apr 26 '21 at 18:42
  • nothing works for me in chrome. still. – deebs May 25 '21 at 14:15
784

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"

Lee Taylor
  • 6,091
  • 14
  • 26
  • 43
mike nelson
  • 18,814
  • 13
  • 59
  • 66
  • For the workaround solution: wouldn't this make the password field autofilled nevertheless ? And thank you for the edit solution. I would leave only that as an answer. – Nicu Surdu May 08 '13 at 09:03
  • Good point, removed that workaround and now just has the solution. – mike nelson May 09 '13 at 00:17
  • 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. – lucasarruda Sep 11 '13 at 21:49
  • Excellent answer for the reason. For the solution, I'm trying this, as well as http://stackoverflow.com/q/10938891/292060. I'd prefer to turn off autofill, but keep autocomplete. – goodeye Oct 26 '13 at 00:25
  • 7
    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) – parliament May 05 '14 at 19:00
  • 20
    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 :( – Tominator May 14 '14 at 07:47
  • 13
    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. – Jammer Jun 01 '14 at 19:52
  • 1
    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. – mike nelson Jun 02 '14 at 07:45
  • 5
    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. – carbontwelve Jun 12 '14 at 15:50
  • 4
    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: https://code.google.com/p/chromium/issues/detail?id=352347 – Mark42 Aug 13 '14 at 18:10
  • 2
    you can remove the name attributes so these fake params aren't posted to server – Patrick Cullen Sep 20 '14 at 22:30
  • 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. – qmo Dec 08 '14 at 18:09
  • @qmo - why did you have to do that? It usually works fine having both fake user and fake password before the real ones. – mike nelson Dec 08 '14 at 22:04
  • @mikenelson It didn't work for me, Chrome picked up the fake username + the real password. Btw, I'm using Chrome 39. – qmo Dec 09 '14 at 21:19
  • @Mark42 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. – Ian Boyd Feb 11 '15 at 14:50
  • 2
    Even better: remove the `name=""` attributes on both inputs and that information never even gets posted to your server, but it still fools Chrome. – praniclift Mar 16 '15 at 06:52
  • Yes it does. I just used the above solution. And your jsbin works as well. Chrome 41. :) – Magnus Eriksson Mar 31 '15 at 16:16
  • 1
    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 :/ – Yesudass Moses Apr 06 '15 at 12:45
  • 2
    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. - – ng-darren Apr 17 '15 at 06:48
  • 10
    try autocomplete="false" not autocomplete="off" – roughcoder Apr 21 '15 at 10:20
  • 297
    This attribute is also required: `autocomplete="I told you I wanted this off, Google. But you would not listen."` – rybo111 Jun 13 '15 at 21:45
  • 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. – cyberskunk Jun 16 '15 at 16:59
  • @MagnusEriksson: No. The jsbin does not work. Chrome 43.0.2357.134 – Jim G. Jul 21 '15 at 21:29
  • Yes, I can confirm that next to the 2 fake fields, you need autocomplete="off" in your form element. This is hilarious :) – Mattijs Aug 25 '15 at 14:24
  • 1
    @roughcoder what autocomplete=false did not make it work. Its the same as autocomplete=off, chrome doesnt care – artdias90 Sep 17 '15 at 08:01
  • 4
    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. – H. Ferrence Oct 29 '15 at 23:51
  • 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. – Olivier Pons Dec 18 '15 at 10:30
  • 1
    It looks like this just stopped working in Chrome v48.0.2564.82 m – Victor F Jan 27 '16 at 13:10
  • 5
    Yes it stopped working - it's like an arms race. I solved it with:
    – Adam Jimenez Jan 29 '16 at 20:27
  • 3
    @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. – Victor F Feb 01 '16 at 17:24
  • @VictorF Ahh, thanks for the heads up I will use that also. It's like an arms race! – Adam Jimenez Feb 02 '16 at 08:39
  • @mikenelson: any idea why the solution (fakeusernameremembered) works? – Stijn Geukens Feb 02 '16 at 21:11
  • 1
    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) – Liorsion Feb 25 '16 at 04:59
  • 4
    @Liorsion 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 fields – ymerej Mar 08 '16 at 16:10
  • 2
    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! – Colin Wiseman Mar 29 '16 at 11:16
  • 1
    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. – Ixalmida May 17 '16 at 17:02
  • I concur with @Ixalmida - 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. – rybo111 Jun 01 '16 at 23:13
  • 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 Chrome – Jack Jun 12 '16 at 10:06
  • 3
    This does not work. Use `autocomplete="new-password"` (http://stackoverflow.com/a/30976223/1438029). Verified works in Version 51.0.2704.79 m. – Geoffrey Hale Jun 14 '16 at 22:39
  • 3
    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.81 – dlsso Jul 21 '16 at 01:33
  • 1
    It stinks that there is not a better solution than this... (no offense to you @mikenelson) offense to google chrome. – Travis Tubbs Feb 08 '17 at 19:32
  • 4
    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. – Brian Chance Feb 09 '17 at 20:57
  • Stopped working on Chrome 56.0.2924.87 . But the autocomplete="off" on the input worked. – Sajjan Sarkar Feb 21 '17 at 18:12
  • the fake fields need to be after your real user/psw fields in dom - works in any browser (win & mac) for me. – Mayrhofer May 02 '17 at 04:58
  • 2
    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? – jtate Jul 07 '17 at 13:50
  • Having problems with Chrome 59 as well. – Victor Soto Jul 13 '17 at 02:32
  • 2
    I was able to get this working again. `style="height:0px; opacity:0"` – The Lazy Coder Jul 17 '17 at 19:22
  • Tried this in Chrome 60 and doesn't appear to work :(, feels like IE hacking all over again... – Mike Purcell Aug 28 '17 at 19:05
  • This doesn't work in Chrome 61 as well. Has anyone found any solution to this? – Yuvraj Oct 10 '17 at 11:46
  • 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 :) – Caius Jard Jan 09 '18 at 14:50
  • 1
    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. – Regular Jo Mar 10 '18 at 04:01
  • 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)) – tleveque Apr 24 '18 at 11:49
  • @Mark42 "_it's usually for a good reason_" It's often for a bad reason (security). Hence, the arm race. – curiousguy May 11 '18 at 17:36
  • @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 :) – dubrox May 29 '18 at 20:04
  • 2
    @mikenelson Since the `autocomplete` attribute doesn't seem to be doing much lately, I posted an [answer](https://stackoverflow.com/questions/15738259/disabling-chrome-autofill/51656048#51656048) 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 :) – Zenoo Aug 02 '18 at 14:50
  • @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 unfortunately – mike nelson Aug 02 '18 at 20:07
  • 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. – Cam Tullos Aug 09 '18 at 19:51
  • Sorry... meant autocomplete='off' – Cam Tullos Aug 09 '18 at 20:07
  • @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. – png Aug 10 '18 at 17:58
  • 3
    autocomplete="off" is working again now as of Chrome Version 68.0.3440.106 (Official Build) (64-bit) – mothmonsterman Aug 30 '18 at 17:38
  • With chrome 69.xxx, I done that to remove stop autocomplete `` – Camille Oct 09 '18 at 21:28
  • You should edit the question, autocomplete="off" works fine in todays Google Chrome. – Esko Oct 31 '18 at 08:34
  • 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) – Zabba Nov 06 '18 at 01:17
  • A new approach that I have not seen: The autofill menu in chrome relies on the input type name. – scrfix Feb 05 '19 at 04:29
  • 4
    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: 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. – scrfix Feb 05 '19 at 04:42
  • But the suggest will popup as usual when I focus a password type input. – Fitz Aug 27 '19 at 06:55
  • 2
    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 ;) – Andres Paul Oct 21 '19 at 09:28
  • I've just used
    in chrome and it works for me
    – GDY Feb 07 '20 at 11:10
  • As I noticed, autocomplete="off" works on Chrome 80, IF there is less than 3 elements in
    . I don't know what is the logic or where the related documentation about it.
    – anilyeni Mar 27 '20 at 01:42
  • 3
    `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 parameter – Pankaja Gamage May 03 '20 at 19:25
  • 74
    `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! – Alex from Jitbit May 16 '20 at 18:24
  • Just tried `chrome-off`, didn't work for me, wtf! Chrome 81 – Vladimir May 16 '20 at 22:02
  • 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. `` 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. – sagar1025 Jun 05 '20 at 16:36
  • @sagar1025 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 password – auron344 Jun 26 '20 at 15:18
  • 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. – Googie Jul 20 '20 at 21:06
  • regarding the new-password, you can read here the expected behaviour. Scroll to "The autocomplete attribute and login fields". https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion – alfoks Jul 22 '20 at 13:23
  • Hello. Had to use `autocomplete="off"`. Chrome version 85+. – Dustexe Oct 14 '20 at 08:27
  • 1
    Here are two Chrome issues you can comment on if you want them to change this behavior: https://bugs.chromium.org/p/chromium/issues/detail?id=587466 and https://bugs.chromium.org/p/chromium/issues/detail?id=914451 – sandstrom Nov 17 '20 at 09:50
  • 1
    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. – Gökhan Kurt Nov 23 '20 at 08:15
  • For people using the fake hidden field remembrer to to add a `tabindex="-1"` to avoid the tab disappearing. – Shadoweb Dec 06 '20 at 11:24
  • I get good explaination here https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion – Muhammad Rosyid Feb 25 '21 at 07:37
  • not working on chrome 88 :( – Sandeep J Patel Apr 08 '21 at 05:27
  • 2018th solution works in 2020 for me.. Thanks for such a long answer!! – Thameem May 13 '21 at 06:54
  • This worked for me: Setting
    – Gopal Mishra May 24 '21 at 08:58
  • None of these work for me, I give up. Congratulations Chrome you win. – demoncodemonkey May 27 '21 at 11:06
283

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>
rmcsharry
  • 4,357
  • 4
  • 50
  • 87
Fery Kaszoni
  • 3,740
  • 1
  • 16
  • 11
  • It does work very well Aaron, in all major browsers ;) – Fery Kaszoni May 04 '15 at 19:58
  • 8
    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) – Dvd Franco May 27 '15 at 03:25
  • 48
    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". – genkilabs May 28 '15 at 16:18
  • 4
    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... – rybo111 Jun 13 '15 at 21:41
  • 3
    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. – Adriano Rosa Jul 02 '15 at 21:54
  • It might not work on old browsers, base on a old 2005 post from Scott Hanselman's blog: http://www.hanselman.com/blog/TurningOffAutoCompleteForTextBoxesInIEAndFireFox.aspx – DestyNova Jul 08 '15 at 11:48
  • 1
    I would not recommend this solution. Setting autocomplete to "false" works in Chrome but FireFox ignores it. – Noel Abrahams Aug 03 '15 at 17:20
  • Noel Abrahams, the question here was about Chrome and not about Firefox! – Fery Kaszoni Aug 04 '15 at 17:11
  • 3
    doesnt work with Chrome 44.0.2403.157. How can this feature work and not work with different versions. It is ridiculous – Mattijs Aug 25 '15 at 14:16
  • 1
    This solution briefly worked, I guess. Not so much anymore. At least, not in our angular site. – MrBoJangles Sep 03 '15 at 23:18
  • See my answer here for a reliable workaround: http://stackoverflow.com/questions/12374442/chrome-browser-ignoring-autocomplete-off/30873633#30873633 – J.T. Taylor Sep 16 '15 at 22:14
  • @GrahamT Might want to check your code, I just updated to 46.0.2490.80 m and it works. – The Muffin Man Oct 24 '15 at 20:45
  • @Toolkit Works for me on Chrome 46.0.2490.80. I think it's something other than browser version that's the problem. – dlsso Nov 17 '15 at 23:09
  • 1
    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! – Theo Orphanos Dec 29 '15 at 18:11
  • I tried all the previously mentioned fixes and none worked for me on Version 47.0.2526.111 (64-bit) – Tom Rossi Jan 28 '16 at 16:19
  • This actually killed the entire form autofill options not just the field for me. – David Feb 18 '16 at 19:16
  • FWIW, google's latest explanation: https://developers.google.com/web/updates/2015/06/checkout-faster-with-autofill. "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." – MSC Mar 12 '19 at 23:42
  • 1
    Does NOT work as of Chrome 75.0.3770.142. Chrome is a mess. – Jeffz Aug 05 '19 at 23:39
  • 2
    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.
    – Jon Ediger Aug 13 '19 at 20:32
  • 1
    `autocomplete="new-password"` and **not using** input name as "password" worked for me. – hkarask Oct 22 '19 at 02:47
  • 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. – SamJakob Oct 28 '19 at 01:03
131

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.

Cœur
  • 32,421
  • 21
  • 173
  • 232
dsuess
  • 4,769
  • 2
  • 20
  • 21
  • 12
    what a great fix :) you should replace jquery with this: this.removeAttribute("class") – Roey Feb 09 '15 at 11:52
  • I used this to stop a dropdwonlist from being autofilled. But also restyled readonly so it didn't look it. Cool idea! – ComfortablyNumb Mar 17 '15 at 14:18
  • @kentcdodds: **Chrome update:** Google released [Chrome v41](http://googlechromereleases.blogspot.de/2015/03/stable-channel-update_19.html) 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. – dsuess Mar 21 '15 at 12:08
  • In Chrome, the readonly attribute trumps the required attribute on an input which breaks client side validation. – Clint May 05 '15 at 16:34
  • 1
    @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** :) – dsuess May 05 '15 at 20:05
  • This is not an elegant solution, using bootstrap the field is styled as a readonly input but this is not one. – Loenix Jun 01 '15 at 10:14
  • @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, dsuess – dsuess Jun 01 '15 at 19:59
  • @dsuess 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). http://api.jquery.com/one/ – Loenix Jun 02 '15 at 05:44
  • 1
    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? – rybo111 Jun 13 '15 at 22:02
  • 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. – johntrepreneur Mar 09 '18 at 18:58
  • 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 perfectly – Khaleel Apr 23 '18 at 09:18
  • not working in Chrome 67, in Firefox 60 only on first focus, then with no readonly attribute it keeps offering stored passwords for certain user – sKopheK Jun 12 '18 at 13:06
  • @dsuess I am still getting autocomplete box on this example https://jsfiddle.net/danielsuess/n0scguv6/. Google Chrome Version 71.0.3578.98 (Official Build) (64-bit) , OS X Mojave. – Primoz Rome Jan 10 '19 at 08:42
  • Chrome version 72.0.3626.121 (Official Build) (64-bit), This is the only solution that worked for me... – Dzak Mar 04 '19 at 05:36
  • For my purposes I needed to insure the field didn't get auto populated AFTER it lost focus. `` – Matt Smith May 06 '19 at 08:18
  • 1
    Apparently google is trying to make decisions for all of us here, they closed the ticket regarding autocomplete="off": https://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: https://bugs.chromium.org/p/chromium/issues/detail?id=587466 – Norman Xu Sep 01 '19 at 22:52
  • I prefer to use this instead: `` – Appoodeh May 24 '21 at 04:46
92

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

dana
  • 14,964
  • 4
  • 53
  • 82
  • 1
    Yes! :) Thank you! This works in Chrome 67.0.3396.99. (I think your link should be: https://www.w3.org/wiki/HTML/Elements/input/search as of September 2018). – Andy King Aug 31 '18 at 08:36
  • 5
    Finally! still works Version 69.0.3497.100 (Official Build) (64-bit) This should be the real answer! – Venson Oct 02 '18 at 11:30
  • 2
    everybody is right and wrong and the same time you should write autocomplete="off" inside the tag
    instead on input and this will stop the autofill behavior
    – demopix Dec 18 '18 at 14:59
  • 1
    Confirmed - this is the only correct answer here that doesn't break proper form structure. Works as of Dec 2018 in all current browsers –  Dec 27 '18 at 16:48
  • 2
    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 – John Jan 09 '19 at 17:51
  • 9
    After Chrome version 72.XX, this fix does not work. Find the lastest fixe here https://stackoverflow.com/a/55045439/1161998 – Adheep Mohamed Abdul Kader Mar 07 '19 at 13:57
  • 1
    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. – Joshua Soileau Mar 25 '20 at 21:19
  • 1
    Top answer, works! – Server Khalilov Dec 07 '20 at 17:01
  • 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; } } – Artyom Krasnyuk May 27 '21 at 10:34
65

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.

arun
  • 3,637
  • 3
  • 27
  • 53
Jobin
  • 7,778
  • 1
  • 29
  • 50
  • This doesn't work well for me: chrome still autofills the password field visibly, while the username is indeed hidden. – Tominator May 14 '14 at 15:26
  • yes its not for password its for user name if you need password too try to create a password fake field too.check my edit – Jobin May 14 '14 at 15:41
  • 1
    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. – Jeffrey Simon Jul 25 '14 at 19:48
  • 2
    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). – MrBoJangles Oct 06 '14 at 23:22
  • 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? – Jeffrey Simon Oct 08 '14 at 01:00
  • 1
    @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). – mike nelson Mar 22 '15 at 07:14
  • 1
    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! – rybo111 Jun 13 '15 at 21:55
  • 2
    Update: This continues to work over a year since the last time I implemented it. We may have a solid winner here. – MrBoJangles Sep 03 '15 at 23:23
  • wow Chrome, you surprise me, is there some bug submitted or whatever? – Toolkit Nov 18 '15 at 02:25
  • 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. – scebotari66 Feb 15 '16 at 06:33
  • `
    ` worked for me in Chrome 50something
    – Urs May 07 '16 at 19:59
  • 1
    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. – Mikal Schacht Jensen Jan 24 '17 at 10:11
  • 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: https://jsfiddle.net/mfdc22pz/ – Moos May 24 '18 at 01:05
  • 1
    This no longer works for me in 69.0.3497.100 (October, 2018). – Matt Oct 08 '18 at 22:10
61

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.

Pang
  • 8,605
  • 144
  • 77
  • 113
Tauras
  • 3,318
  • 3
  • 19
  • 31
52

For me, simple

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

Did it.

Tested on multiple versions, last try was on 56.0.2924.87

Kuf
  • 15,678
  • 4
  • 61
  • 85
  • @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? – Kuf Feb 28 '17 at 21:04
  • 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. –  Mar 22 '17 at 08:09
  • 1
    @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? – Kuf Mar 22 '17 at 14:26
  • Working in Version 63.0.3239.132 – albertski Jan 25 '18 at 16:06
  • 3
    Version 64.0.3282.186 (Official Build) (64-bit) Windows. 2018-03-01 NOT WORKING for disabling autofill. – billy jean Mar 21 '18 at 19:12
  • Worked Google Chrome 67.0.3396.99 (Official Build) (64-bit) (cohort: Stable) – Matt Morgan Jul 20 '18 at 17:41
  • 2
    Pretty sure this removes the form / input from assistive technologies https://w3c.github.io/using-aria/#ariapresentation – Olex Ponomarenko Feb 01 '19 at 16:27
  • this is the only working thing in chrome 88 at Mac at the moment. – Oleg Abrazhaev Apr 15 '21 at 13:44
29

You have to add this attribute :

autocomplete="new-password"

Source Link : Full Article

Hitesh Kalwani
  • 484
  • 5
  • 8
20

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;"/>
    
Fareed Alnamrouti
  • 26,439
  • 4
  • 77
  • 71
  • 1
    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! –  Mar 18 '16 at 03:06
  • Unfortunately, does not work for regular TextBox inputs. – eYe Mar 31 '16 at 15:21
  • 1
    actually it is working just set the name property ;) – Fareed Alnamrouti Apr 01 '16 at 05:26
  • 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. – cristiancastrodc Jun 02 '17 at 15:36
  • 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. – IQtheMC May 09 '18 at 22:25
  • 1
    Works on Chrome 67.0 on angular html component ` – Junior Mayhé Jul 20 '18 at 15:52
  • Confirmed this is working Chrome: 71.0 for putting a dummy password element as the first element in your form immediately after
    open tag - sooo happy!
    – Adam Feb 15 '19 at 08:55
  • 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. strange – V H Oct 02 '19 at 10:50
  • Super, thank you, after searching and trying, this finally solved it! – eheydenr Oct 14 '20 at 19:33
19

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. your@email.com), 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="your@email.com">
<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.

rybo111
  • 10,836
  • 3
  • 55
  • 62
  • @Vaia - have you tried navigating to another page and then pressing the back button? I get mixed results - it may need tweaking. – rybo111 Jun 17 '15 at 14:13
  • 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. @rybo111 – AlexioVay Jun 17 '15 at 14:19
  • @Vaia I meant option 2 - please reply here if you encounter any problems. Thanks. – rybo111 Jun 17 '15 at 14:20
17

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;
}
Stiffels
  • 307
  • 2
  • 4
  • best approach I found so far! well, at least for Chrome 64 :/ – scipper Feb 01 '18 at 13:34
  • 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! – Doug McLean Nov 20 '18 at 17:20
  • "text-security" is not a valid css property as of october 2020 – samthet Oct 08 '20 at 15:03
16

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"
  • **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. – Regular Jo Mar 09 '18 at 23:45
  • 4
    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! – billy jean Mar 21 '18 at 19:26
  • 2
    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 me – ChronoFish Jul 12 '18 at 13:51
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.

Rob Jensen
  • 221
  • 2
  • 6
  • 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... – Joe Heyming Dec 15 '15 at 20:02
12

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.

Shoaib Khan
  • 88
  • 1
  • 9
Momin
  • 356
  • 3
  • 5
12
<input readonly onfocus="this.removeAttribute('readonly');" type="text">

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

Avindu Hewa
  • 1,192
  • 1
  • 11
  • 20
10

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'">
falsarella
  • 11,640
  • 8
  • 65
  • 104
Bernesto
  • 927
  • 11
  • 17
  • 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: http://jsbin.com/jacizu/2/edit – kentcdodds Mar 20 '15 at 22:47
  • 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. – Bernesto Mar 21 '15 at 02:43
  • 4
    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. http://jsbin.com/pujasu/1/edit – Bernesto Mar 21 '15 at 02:58
  • actually... it seemed to work for your example, but for some reason it's not working for me :-( – kentcdodds Mar 21 '15 at 03:49
  • Ha! That's why it's called a hack... Do you have an example you can share where it's not working? – Bernesto Mar 21 '15 at 14:36
  • Great this is the only one that worked on v49 for me Thanks – Liam Mar 25 '16 at 15:59
  • 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. :( – Mike Purcell Aug 30 '17 at 15:19
  • With chrome 69.xxx, I done that to remove stop autocomplete `` – Camille Oct 09 '18 at 21:28
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">
mccainz
  • 3,378
  • 5
  • 32
  • 44
  • As for June of 2016 and Chrome 51.0.2704.106 m this is the only working solution over here – Denis Jun 29 '16 at 14:46
  • But will the form select the right (visible) input field you need then? Because it's the same name. – AlexioVay Jul 03 '16 at 07:33
  • @Vaia, adding the disabled attribute to the duplicate element will prevent it from being submitted. – mccainz Sep 13 '16 at 17:24
8

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>
Mike
  • 640
  • 12
  • 35
norekhov
  • 2,557
  • 18
  • 34
  • 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! – Douwe de Haan Jun 21 '18 at 09:27
  • 1
    @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? – digout Jan 07 '19 at 10:11
  • @digout I agree. A good example would be to use the UUID for this kind of stuff. Just make sure that the string is unique! – Douwe de Haan Jan 07 '19 at 10:29
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/

Ryan Grush
  • 1,845
  • 2
  • 33
  • 56
  • 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 :-( – kentcdodds Mar 20 '15 at 22:45
  • 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! +1 – Louys Patrice Bessette Mar 30 '17 at 20:38
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

MZaragoza
  • 9,447
  • 9
  • 60
  • 96
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

MagicSux
  • 373
  • 3
  • 9
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');
}
Abela
  • 1,175
  • 1
  • 15
  • 37
Priyanka
  • 93
  • 1
  • 2
  • awesome awesome solutions – DKR Dec 04 '19 at 09:08
  • 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. – Avatar Mar 18 '20 at 11:28
6

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.

Chris Pratt
  • 207,690
  • 31
  • 326
  • 382
  • The first part of this answer doesn't doesn't appear to be true anymore: [Chrome Bug](https://bugs.chromium.org/p/chromium/issues/detail?id=587466&can=2&start=0&num=100&q=&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified&groupby=&sort=) – Joshua Drake Apr 09 '19 at 18:33
  • 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. – Chris Pratt Apr 09 '19 at 18:42
  • We have a couple of cases where autocomplete="off" is not being respected by Chrome. – Joshua Drake Apr 11 '19 at 13:17
  • 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. – Chris Pratt Apr 11 '19 at 13:52
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

mumair
  • 2,456
  • 26
  • 37
6

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" />
5

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>
hyper_st8
  • 311
  • 7
  • 6
5

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.

Michael.
  • 864
  • 12
  • 15
  • 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. – epelc Mar 06 '16 at 04:17
5

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

eug
  • 1,088
  • 1
  • 17
  • 24
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">
Thuong
  • 544
  • 4
  • 12
3

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

$(document).ready(function(e) {
    if ($.browser.webkit) {
        $('#input_id').val(' ').val('');
    }
});
3

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

Mr Lister
  • 42,557
  • 14
  • 95
  • 136
Deminetix
  • 2,266
  • 20
  • 21
  • 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. – wsyq1n Feb 22 '21 at 22:41
3

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.

CodeSimian
  • 67
  • 2
  • 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) – danjarvis Oct 18 '16 at 18:48
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

Isaac Limón
  • 1,326
  • 14
  • 12
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.

lufc
  • 1,826
  • 2
  • 12
  • 18
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.

1

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

Iamzozo
  • 2,301
  • 15
  • 20
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');
bocapio
  • 99
  • 4
1

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"/>
Juan Carrey
  • 676
  • 1
  • 6
  • 13
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.

Colin Wiseman
  • 838
  • 6
  • 9
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

michalzuber
  • 4,493
  • 1
  • 25
  • 28
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.

Jeffrey Holmes
  • 305
  • 3
  • 11
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>
Rikku121
  • 2,171
  • 2
  • 19
  • 34
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.
rak007
  • 886
  • 10
  • 21
Karan Vyas
  • 99
  • 1
  • 4
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);
    }

});
EngineerCoder
  • 1,373
  • 13
  • 26
1

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.
        });
    } 
SaidbakR
  • 11,955
  • 16
  • 89
  • 173
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.

David Adams
  • 479
  • 6
  • 8
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.

Hemant_Negi
  • 1,555
  • 14
  • 22
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'

Geoff Kendall
  • 1,003
  • 10
  • 11
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>
antoine129
  • 4,484
  • 4
  • 29
  • 50
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.

andrewsi
  • 10,954
  • 132
  • 33
  • 48
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"/>
typocoder
  • 195
  • 1
  • 1
  • 9
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>
MiVvlt
  • 71
  • 11
  • 1
    This does not work, both inputs, fake and new are yellow-autocompleted :( – Arnold Roa Feb 28 '17 at 11:20
  • 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? – MiVvlt Mar 01 '17 at 12:17
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();
kofifus
  • 11,635
  • 8
  • 73
  • 114
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'}})
....
tutak
  • 1,075
  • 1
  • 14
  • 28
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);
            });
});
J0ANMM
  • 5,707
  • 7
  • 41
  • 75
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.

alehro
  • 2,131
  • 2
  • 24
  • 38
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')
    }
  }
coder9
  • 1,551
  • 1
  • 27
  • 51
0

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
yivi
  • 23,845
  • 12
  • 64
  • 89
w3jimmy
  • 662
  • 10
  • 20
  • It doesn't work. I'm trying with Chrome 67. Nothing. I still need a fake input with `display: none`! Very crazy! –  May 30 '18 at 22:47
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.
frin
  • 4,243
  • 3
  • 26
  • 23
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);
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.

Iwan Ross
  • 164
  • 2
  • 8
  • 1
    While this code snippet may be the solution, [including an explanation](https://meta.stackexchange.com/questions/114762/explaining-entirely-%E2%80%8C%E2%80%8Bcode-based-answers) 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. – L. Guthardt Mar 21 '18 at 09:49
  • The first colon in the 2nd line is probably a typo. – SantiBailors Apr 06 '18 at 08:50
  • I agree with L. Guthardt. Please provide a complete example that showcases your solution, preferably on jsfiddle, jsbin, codepen or similar demo website. – Johannes Apr 08 '18 at 22:28
-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.

Zei
  • 76
  • 10
-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;" />
MikeC
  • 275
  • 3
  • 13
-1

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>
hass.
  • 12
  • 5
-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.

-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.

Jan DB
  • 175
  • 1
  • 5
-7

This is the most recent solution that I have used.

$('#email').prop('autocomplete', true);
Edvard Åkerberg
  • 1,901
  • 1
  • 20
  • 39