casraf casraf - 1 year ago 78
CSS Question

Override browser form-filling and input highlighting with HTML/CSS

I have 2 basic forms -- sign in and sign up, both on the same page. Now, I have no problem with the sign in form auto-filling, but the sign up form auto fills as well, and I don't like it.

Also, the form styles get a yellow background which I can't manage to override and I don't want to use inline CSS to do so. What can I do to make them stop being colored yellow and (possibly) auto filling? Thanks in advance!

Answer Source

for the autocompletion, you can use:

<form autocomplete="off">

regarding the coloring-problem:

from your screenshot i can see that webkit generates the following style:

input:-webkit-autofill {
    background-color: #FAFFBD !important;

1) as #id-styles are even more important than .class styles, the following may work:

#inputId:-webkit-autofill {
    background-color: white !important;

2) if that won't work, you can try to set the style via javascript programmatically

$("input[type='text']").bind('focus', function() {
   $(this).css('background-color', 'white');

3) if that won't work, you're doomed :-) consider this: this wont hide the yellow color, but will make the text readable again.

input:-webkit-autofill {
        color: #2a2a2a !important; 

4) a css/javascript solution:


input:focus {
    background-position: 0 0;

and the following javascript has to be run onload:

function loadPage()
    if (document.login)//if the form login exists, focus:
    {;//the username input
        document.login.pass.focus();//the password input
        document.login.login.focus();//the login button (submitbutton)


<body onload="loadPage();">

good luck :-)

5) If none of the above work try removing the input elements, cloning them, then placing the cloned elements back on the page (works on Safari 6.0.3):

function loadPage(){

    var e = document.getElementById('id_email');
    var ep = e.parentNode;
    var e2 = e.cloneNode();

    var p = document.getElementById('id_password');
    var pp = p.parentNode;
    var p2 = p.cloneNode();

document.body.onload = loadPage;

6) From here:

if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
            var text = $(this).val();
            var name = $(this).attr('name');
            $('input[name=' + name + ']').val(text);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download