This feature is well established and works across many devices and browser versions. It’s been available across browsers since February 2023.
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.
label {
display: block;
margin-top: 1em;
}
input:is(:-webkit-autofill, :autofill) {
border: 3px solid darkorange;
}
<form> <p>Click on the text box and choose any option suggested by your browser.</p> <label for="name">Name</label> <input id="name" name="name" type="text" autocomplete="name" /> <label for="email">Email Address</label> <input id="email" name="email" type="email" autocomplete="email" /> <label for="country">Country</label> <input id="country" name="country" type="text" autocomplete="country-name" /> </form>
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.
:autofill {
/* ... */
}
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>
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
:autofill |
1101 | 11079 | 8686 | 9615 | 153 | 11018 | 8686 | 7414 | 151 | 21.01.0 | 1104.4 | 151 |
:-moz-autofill pseudo-class on input elements with an autofilled value
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/:autofill