:autofill
Baseline 2023
Newly available
Since February 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The :autofill
CSS pseudo-class matches when an <input>
element has its value autofilled by the browser. The class stops matching if the user edits the field.
Try it
Note: 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. For example Chrome has the following in its internal stylesheet:
background-color: rgb(232 240 254) !important;
background-image: none !important;
color: -internal-light-dark(black, white) !important;
This means that you cannot set the background-color
, background-image
, or color
in your own rules.
Syntax
:autofill {
/* ... */
}
Examples
The following example demonstrates the use of the :autofill
pseudo-class to change the border of a text field that has been autocompleted by the browser.
To ensure we don't create an invalid selector list, both :-webkit-autofill
and :autofill
are matched using a forgiving selector list with :is()
.
input {
border-radius: 3px;
}
input:is(:-webkit-autofill, :autofill) {
border: 3px dotted orange;
}
<form method="post" action="">
<label for="email">Email</label>
<input type="email" name="email" id="email" autocomplete="email" />
</form>
Specifications
Specification |
---|
HTML Standard # selector-autofill |
Browser compatibility
BCD tables only load in the browser
See also
- Chromium issue 46543: Auto-filled input text box yellow background highlight cannot be turned off
- WebKit bug 66032: Allow site authors to override autofilled fields' colors.
- Mozilla bug 740979: implement
:-moz-autofill
pseudo-class on input elements with an autofilled value - User Interface Module Level 4: more selectors