28

I've managed to change the background color of an autofilled input field from yellow to white with the following code:

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

However, changing the font color to grey simply by adding color: #999; doesn't work. How could I fix this? Many thanks!

TheLeonKing
  • 3,501
  • 7
  • 32
  • 44

3 Answers3

47

Try the below CSS

input:-webkit-autofill {
    -webkit-box-shadow:0 0 0 50px white inset; /* Change the color to your own background color */
    -webkit-text-fill-color: #999;
}
input:-webkit-autofill:focus {
    -webkit-box-shadow: /*your box-shadow*/,0 0 0 50px white inset;
    -webkit-text-fill-color: #999;
}
Kawinesh S K
  • 3,148
  • 1
  • 16
  • 29
16

Try the below CSS:

/* Change Autocomplete styles in Chrome*/
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus
input:-webkit-autofill, 
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
  border: 1px solid green;
  -webkit-text-fill-color: green;
  -webkit-box-shadow: 0 0 0px 1000px #000 inset;
  transition: background-color 5000s ease-in-out 0s;
}

We can use the -webkit-autofill pseudo-selector to target those fields and style them as we see fit.

Mahdi Afzal
  • 729
  • 10
  • 14
-3
input:-webkit-autofill {
    color: #999 !important;
}

This would work for you!

  • 1
    You didn't even do it correctly.... Also no, don't use `!important`. **Note:** It's like this - `color: #999 !important;` – Ruddy Mar 25 '14 at 10:41
  • @Ruddy:Thanks,I have updated my answer. Could you please tell me, why we should not use important? I'm not much familiar with css, but I knw the answer, so replied. –  Mar 25 '14 at 10:52
  • 1
    Take a look at this [**page**](http://css-tricks.com/when-using-important-is-the-right-choice/). Its a good little read. For this I don't feel there is a need to use `!important` just feels lazy when there are another ways to do it. – Ruddy Mar 25 '14 at 10:57
  • 4
    @Ruddy: Thanks, quite useful for me :) –  Mar 25 '14 at 11:34