Google Chrome form autofill and its yellow background
Asked Answered
B

29

250

I have design problem with Google Chrome and its form autofill function. If Chrome remembers some login/password it changes a background color to a yellow one.

Here are some screenshots:

alt text alt text

How to remove that background or just disable this autofill ?

Brindisi answered 27/5, 2010 at 10:30 Comment(11)
I'd also like to see if there's an answer to this.Herbal
For styling, this colour can seriously with design elements, like the outlining in input tags in Chrome also, I would more like to change the colour than turn it off.Herbal
Google seems to acknowledge this issue to some degree. See code.google.com/p/chromium/issues/detail?id=46543Tipperary
@ANeves Well this is a major issue when you have an heavy design site where you use background or sprite methods to show the user what's is the desire value in a specify field. So if chrome override this background-image whith their background-color, Users wont see what you want to show them.Avar
ANeves - the reason I need to disable autofill is because the user will be a manager who will use this page to add other users to the system, so the last thing he wants is for it to autofill the manager's username and password. Also I'm finding that the Password box gets coloured, but the Retype Password box does not.Halfdan
@ANeeves A concrete example of why I'm doing this (and why I'm here) is that the Chrome automatic styling when auto filling makes a background image disappear on the username / password input. When not auto filling, there is a User & Password icon inside each input. Not so 'beyond comprehension' :)Horologium
Rather than disabling the yellow background, just don't use images for your forms and it will look much better than that: i.imgur.com/DemnvGy.pngEisenstark
To disable autocomplete you can add autocomplete="off" to your input element, e.g. <input type="text" id="input" autocomplete="off">Pietrek
Just an additional info: I was bitten by this when I have a password field. I got my fields highlighted automatically (yellow) and filled with strange value. And I found the solution here: zigpress.com/2014/11/22/stop-chrome-messing-forms ... The solution is in the section that says "Disable Google Chrome Autofill" ... add hidden fields.Inaudible
Please check my workaround here: https://mcmap.net/q/57902/-disabling-chrome-autofill/…Ostiary
@Brindisi Please reconsider changing the marked answer, mine no longer applies and another answer is a far better solution.Herbal
O
286

Change "white" to any color you want.

input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px white inset !important;
}
Ostiary answered 7/1, 2013 at 23:37 Comment(16)
great idea. I wouldl stick with 50 or 100 whenever sufficent (regular size input boxes) to avoid potential performance hits on weaker devices. (And no need for px after 0)Lieutenancy
Love this hack! Great thinking... Everyone is removing autofill. I wanted to keep autofill on just get ride of the ugly yellow.Tamatamable
Doesn't work if you have background images behind your input field just fill the whole area with white. I tried all the solutions on this page, including the jquery based ones and they didnt work for me, in the end i had to add autocomplete="off" to the field.Karlykarlyn
A good CSS-only compromise I guess. Please star the reported issue to encourage google devs to fix it code.google.com/p/chromium/issues/detail?id=46543Fawn
Weird, this fixes the color...but now causes Chrome to auto-fill the username/password fields. No Google, I'm not logging in with my "create new user" form...Mcgary
To also style the text color use -webkit-text-fill-color - see this questionTwotone
this removes the other jquery validations and CSS from the textbox :(Mysterious
If you want to retain the original shadow using Bootstrap, you can use: -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), inset 0 0 0 50px white;Bathetic
nice hack! none of other solutions worked for me. i use this box shadow(nee less process): -webkit-box-shadow: inset 0 100px 0 white;Plains
This worked but I had to set the input:-webkit-autofill:focus class too.Impeccable
there is error, i dont maybe syntax changed but this works now: box-shadow: inset 0 0 0 1000px white !important;Cheadle
this is not a good solution because it also hides background images.Grimaud
Yes good hack but unfortunately not working for transparent fields with background images...Sporogonium
what if i need the color to be transparent?Anglice
Does not play well if the field has multiple shadows applied. I have another inset shadow to get the effect of the field being cut out of my page, and in combination with this, the left and right side (with border radius) still becomes yellow. To test: Use a darker color than 'white'.Owl
Good solution xDFevre
F
53

If you guys want transparent input fields you can use transition and transition delay.

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    -webkit-transition-delay: 9999s;
    -webkit-transition: color 9999s ease-out, background-color 9999s ease-out;
}
Ferule answered 10/9, 2015 at 15:37 Comment(4)
Best solution for me as RGBA color values did not work in -webkit-box-shadow. Also eliminates the need to give color values for this declaration: the default values will still apply.Within
even better is to use the transition delay instead of its duration, to not have color mixing at allSubfloor
good but for some reason I had to move this rule at the end of the file, otherwise didn't workedCervix
That what I looked for! Thank you!Unbecoming
M
43

Solution here:

if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
    $(window).load(function(){
        $('input:-webkit-autofill').each(function(){
            var text = $(this).val();
            var name = $(this).attr('name');
            $(this).after(this.outerHTML).remove();
            $('input[name=' + name + ']').val(text);
        });
    });
}
Mccarthyism answered 16/11, 2010 at 16:33 Comment(3)
This did work whereas the top answer did not. However I think I will not try to change the behavior since a). this is javascript so there is a second between it works and it doesn't (until the js loads) and b). it may confuse the chrome user who is used to the default behavior.Bur
My chrome just reapplies the yellow to the new input :(Plyler
Please don't. This will not work with any JS framework, only for static websites.Unbecoming
T
26

In Firefox you can disable all autocomplete on a form by using the autocomplete="off/on" attribute. Likewise individual items autocomplete can be set using the same attribute.

<form autocomplete="off" method=".." action="..">  
<input type="text" name="textboxname" autocomplete="off">

You can test this in Chrome as it should work.

Terrieterrier answered 27/5, 2010 at 10:44 Comment(3)
Turning autocomplete="off" is not accessible these days.Mawson
Unfortunately, this solution no longer works in Chrome.Selle
This is highly disrecommended as you're not really solving the actual problem here. instead, you're creating a new one by frustrating users because they have to manually type their (presumably) login details (if they even remember what they were)Grout
D
25

If you want to preserve the autofill, as well as any data, attached handlers and functionality attached to your input elements, try this script:

if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0)
{
    var _interval = window.setInterval(function ()
    {
        var autofills = $('input:-webkit-autofill');
        if (autofills.length > 0)
        {
            window.clearInterval(_interval); // stop polling
            autofills.each(function()
            {
                var clone = $(this).clone(true, true);
                $(this).after(clone).remove();
            });
        }
    }, 20);
}

It polls until it finds any autofill elements, clones them including data and events, then inserts them into the DOM in the same location and removes the original. It stops polling once it finds any to clone since the autofill sometimes takes a second after page load. This is a variation of a previous code sample, but more robust and keeps as much functionality intact as possible.

(Confirmed working in Chrome, Firefox and IE 8.)

Demur answered 13/7, 2011 at 14:14 Comment(4)
This was the only solution I found working, WITHOUT disabling autocomplete.Kozak
maybe setting intervals is not necessary as chrome autofills on window.load?Statampere
Works without removing auto complete, much better solution than the ones with millions of up votes.Trixy
The other solutions did not work for me, even the most upvoted one, but this one did. The problem, which is the opposite of what @Timo said above, is that Chrome does not autofill right at window.load. Even though this worked, one problem with it is that if there are no -webkit-autofill elements, the loop continuously runs. You don't even need an interval for this to work. Simply set a timeout with maybe a 50 millisecond delay and it will work fine.Forby
P
16

The following CSS removes the yellow background color and replaces it with a background color of your choosing. It doesn't disable auto-fill and it requires no jQuery or Javascript hacks.

input:-webkit-autofill {
    -webkit-box-shadow:0 0 0 50px white inset; /* Change the color to your own background color */
    -webkit-text-fill-color: #333;
}
input:-webkit-autofill:focus {
    -webkit-box-shadow: /*your box-shadow*/,0 0 0 50px white inset;
    -webkit-text-fill-color: #333;
}

Solution copied from: Override browser form-filling and input highlighting with HTML/CSS

Pardoes answered 15/1, 2014 at 16:41 Comment(1)
Does not play well if the field has multiple shadows applied.Owl
D
6

Worked for me, only the css change required.

input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0px 1000px #ffffff inset!important;
}

you can put any color in place of #ffffff.

Danette answered 21/1, 2016 at 9:12 Comment(0)
M
3

A little bit hacky but works perfectly for me

input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0px 1000px white inset;
}
Montagna answered 6/8, 2015 at 12:55 Comment(0)
F
3

A combination of answers worked for me

<style>
    input:-webkit-autofill,
    input:-webkit-autofill:hover,
    input:-webkit-autofill:focus,
    input:-webkit-autofill:active {
        -webkit-box-shadow: 0 0 0px 1000px #373e4a inset !important;
           -webkit-text-fill-color: white !important;
   }
</style>
Furnivall answered 5/2, 2016 at 9:38 Comment(1)
This is the only example that worked for me with both text and background on Chrome Version 53.0.2785.116 mPraise
S
2

Here's the MooTools version of Jason's. Fixes it in Safari too.

window.addEvent('domready',function() { 
    $('username').focus();

    if ((navigator.userAgent.toLowerCase().indexOf(\"chrome\") >= 0)||(navigator.userAgent.toLowerCase().indexOf(\"safari\") >= 0))
    {

        var _interval = window.setInterval(function ()
        {
            var autofills = $$('input:-webkit-autofill');
            if (autofills.length > 0)
            {

                window.clearInterval(_interval); // stop polling
                autofills.each(function(el)
                {
                    var clone = el.clone(true,true).inject(el,'after');;
                    el.dispose();
                });
            }
        }, 20);                                               


    }
});
Sitton answered 8/10, 2012 at 22:29 Comment(1)
Don't use this script. If there are no autofilled elements, the loop will continuously run at 20 milliseconds. An interval is unnecessary. Set a timeout after window.load at around 50 milliseconds and that will be plenty of time to remove the styling.Forby
E
2

This fixes the problem on both Safari and Chrome

if(navigator.userAgent.toLowerCase().indexOf("chrome") >= 0 || navigator.userAgent.toLowerCase().indexOf("safari") >= 0){
window.setInterval(function(){
    $('input:-webkit-autofill').each(function(){
        var clone = $(this).clone(true, true);
        $(this).after(clone).remove();
    });
}, 20);
}
Enneastyle answered 18/1, 2013 at 0:24 Comment(4)
Is what works for me. But the BUG still there, and as can be seen, no date to be fixed. code.google.com/p/chromium/issues/detail?id=46543#c22Ammunition
You never clear your interval. This is sloppy code, don't use it.Forby
Actually this doesnt work. I cant type anything in the inputs since they're constantly getting cloned. almost there...Plyler
try this var id = window.setInterval(function(){ $('input:-webkit-autofill').each(function(){ var clone = $(this).clone(true, true); $(this).after(clone).remove(); }); }, 20); $('input:-webkit-autofill').focus(function(){window.clearInterval(id);});Plyler
H
2

This helped me, a CSS only version.

input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset; }

where white can be any color you want.

Hebrew answered 22/5, 2015 at 23:48 Comment(0)
R
2

I use this,

input:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset !important; }
input:focus:-webkit-autofill { -webkit-box-shadow: 0 0 0px 1000px white inset !important; }
/* You can use color:#color to change the color */
Ronni answered 28/6, 2015 at 10:53 Comment(0)
L
1

In your tag, simply insert this small line of code.

autocomplete="off"

However, do not place this in the username/email/idname field because if you are still looking to use autocomplete, it will disable it for this field. But I found a way around this, simply place the code in your password input tag because you never autocomplete passwords anyways. This fix should remove the color force, matinain autocomplete ability on your email/username field, and allows you to avoid bulky hacks like Jquery or javascript.

Lorollas answered 25/1, 2012 at 1:42 Comment(0)
A
1

If you want to get rid of it entirely, I've adjusted the code in the previous answers so it works on hover, active and focus too:

input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:active, input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px white inset;
}
Actinism answered 3/2, 2015 at 14:1 Comment(1)
add a !important is necessary but thanks, its helped me alot.Farny
A
1

If you want to avoid the yellow flicker until your css is applied slap a transition on that bad boy like so:

input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px white inset !important;
    transition: background-color 10s ease-in-out 0s;
}
Actinotherapy answered 8/10, 2018 at 12:31 Comment(0)
C
0

Here's a Mootools solution doing the same as Alessandro's - replaces each affected input with a new one.

if (Browser.chrome) {
    $$('input:-webkit-autofill').each(function(item) {
        var text = item.value;
        var name = item.get('name');
        var newEl = new Element('input');
        newEl.set('name', name);
        newEl.value = text;
        newEl.replaces(item);
    });
}
Chrisy answered 3/6, 2011 at 9:28 Comment(0)
G
0

What about that solution:

if ($.browser.webkit) {
    $(function() {
        var inputs = $('input:not(.auto-complete-on)');

        inputs.attr('autocomplete', 'off');

        setTimeout(function() {
            inputs.attr('autocomplete', 'on');
        }, 100);
    });
}

It turns off the auto-complete and auto-fill (so yellow backgrounds disappear), waits 100 milliseconds an then turns the auto-complete functionality back without auto-fill.

If you have inputs that need to be auto-filled, then give them auto-complete-on css class.

Giraldo answered 1/2, 2013 at 15:12 Comment(0)
Q
0

None of the solutions worked for me, the username and password inputs were still being populated and given the yellow background.

So I asked myself, "How does Chrome determine what should be autofilled on a given page?"

"Does it look for input ids, input names? Form ids? Form action?"

Through my experimentation with the username and the password inputs, there were only two ways I found that would cause Chrome to not be able to find the fields that should be autofilled:

1) Put the password input ahead of the text input. 2) Give them the same name and id ... or no name and id.

After the page loads, with javascript you can either change the order of the inputs on the page, or dynamically give them their name and id ...

And Chrome doesn't know what hit it ... autocomplete stays off.

Crazy hack, I know. But it's working for me.

Chrome 34.0.1847.116, OSX 10.7.5

Quirk answered 25/4, 2014 at 22:51 Comment(0)
P
0

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

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

I fixed this issue for a password field i have like this:

Set the input type to text instead of password

Remove the input text value with jQuery

Convert the input type to password with jQuery

<input type="text" class="remove-autofill">

$('.js-remove-autofill').val('');    
$('.js-remove-autofill').attr('type', 'password');
Tedium answered 25/6, 2014 at 12:40 Comment(1)
Does not work in Chrome. As soon as the field becomes type=password, Chrome fills it inGearalt
P
0

An update to Arjans solution. When trying to change the values it wouldnt let you. This works fine for me. When you focus on an input then it will go yellow. its close enough.

$(document).ready(function (){
    if(navigator.userAgent.toLowerCase().indexOf("chrome") >= 0 || navigator.userAgent.toLowerCase().indexOf("safari") >= 0){
        var id = window.setInterval(function(){
            $('input:-webkit-autofill').each(function(){
                var clone = $(this).clone(true, true);
                $(this).after(clone).remove();
            });
        }, 20);

        $('input:-webkit-autofill').focus(function(){window.clearInterval(id);});
    }
});

$('input:-webkit-autofill').focus(function(){window.clearInterval(id);});
Plyler answered 30/4, 2015 at 9:50 Comment(0)
G
0

Try this code:

 	$(function(){
   		setTimeout(function(){
   			$('[name=user_password]').attr('type', 'password');
   		}, 1000);
   	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<input name="user_password" type="password">
Grobe answered 21/7, 2015 at 9:11 Comment(0)
S
0

fareed namrouti answer is correct. But the background still get yellow when the input is selected. Adding !important fix the problem. If you want also textarea and select with the same behavior just add textarea:-webkit-autofill, select:-webkit-autofill

Only input

input:-webkit-autofill {
    background-color: rgb(250, 255, 189) !important;
}

input, select, textarea

input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
    background-color: rgb(250, 255, 189) !important;
}
Subsoil answered 25/9, 2015 at 14:45 Comment(0)
E
0

Adding autocomplete="off" is not gonna cut it.

Change input type attribute to type="search".
Google doesn't apply auto-fill to inputs with a type of search.

Hope this saves you some time.

Enameling answered 28/10, 2015 at 16:41 Comment(0)
S
0

The only solution that worked in my case:

:-webkit-autofill {
  -webkit-text-fill-color: #000; /* ok for text, no hack */
  transition-property: background-color; /* begin hack for background... */
  transition-delay: 100000s; /* ...end hack for background */
}

This solution is not ideal, it is while waiting to find better ...

Strep answered 2/9, 2021 at 7:30 Comment(0)
P
-1

The final solution:

$(document).ready(function(){
    var contadorInterval = 0;
    if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0)
    {
        var _interval = window.setInterval(function ()
        {
            var autofills = $('input:-webkit-autofill');
            if (autofills.length > 0)
            {
                window.clearInterval(_interval); // stop polling
                autofills.each(function()
                {
                    var clone = $(this).clone(true, true);
                    $(this).after(clone).remove();
                    setTimeout(function(){
//                        $("#User").val('');
                        $("#Password").val('');
                    },10);
                });
            }
            contadorInterval++;
            if(contadorInterval > 50) window.clearInterval(_interval); // stop polling
        }, 20);
    }else{
        setTimeout(function(){
//            $("#User").val('');
            $("#Password").val('');
        },100);
    }
});
Pennipennie answered 11/4, 2014 at 15:21 Comment(0)
T
-2
<input type="text" name="foo" autocomplete="off" />

Similar Question: Link

Teem answered 13/5, 2014 at 13:59 Comment(2)
chrome ignores the autocomplete="off"Krilov
Disable Autocomplete in Google Chrome: <a href="browsers.about.com/od/googlechrome/ss/…>Teem
R
-5

Just found myself with the same question. This works for me:

form :focus {
  outline: none;
}
Requisition answered 27/5, 2012 at 17:13 Comment(1)
thats the outline on the box when you click in it, not the autofilled input's background colourMydriatic

© 2022 - 2024 — McMap. All rights reserved.