Why is the autofill text color not white in my form input?

I have created an HTML form and I am trying to set the text color of autofilled inputs to white. However, it doesn't seem to be working as expected. Here is my code: https://jsfiddle.net/76crfwjv/1/ input:-webkit-autofill { background-color: #000 !important; color: #fff !important; -webkit-box-shadow: 0 0 0 1000px #000 inset !important; box-shadow: 0 0 0px 1000px #000 inset !important; transition: background-color 5000s ease-in-out 0s; } <form action="/submit-form" method="post"> <label for="name">Name:</label> <input type="text" id="name" name="name" placeholder="Enter your name" required> <button type="submit">Submit</button> </form> Despite setting the color to white using color: #fff !important;, the autofill text remains black. How can I ensure that the autofill text color is white? Are there any known issues or additional CSS rules I need to apply to fix this?
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
5 Replies
Chris Bolson
Chris Bolson4mo ago
It may well be to the browser overriding your styles: According to MDN:
The user agent style sheets of many browsers use !important in their :-webkit-autofill style declarations, making them non-overridable by webpages without resorting to JavaScript hacks
https://developer.mozilla.org/en-US/docs/Web/CSS/:autofill
MDN Web Docs
:autofill - CSS: Cascading Style Sheets | MDN
The :autofill CSS pseudo-class matches when an element has its value autofilled by the browser. The class stops matching if the user edits the field.
Abc
AbcOP4mo ago
Do you know where to find these JavaScript Hacks to change the color?
clevermissfox
clevermissfox4mo ago
If you apply
html {color-scheme: dark;}
html {color-scheme: dark;}
your form fields will set up for dark mode
Abc
AbcOP4mo ago
Thank you both very much.
Chris Bolson
Chris Bolson4mo ago
You could also try -webkit-text-fill-color: white !important; That might work, at least on some browsers.
Want results from more Discord servers?
Add your server