:autofill
Baseline 2023Newly available
Since February 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Please take two minutes to fill out our short survey.
試してみましょう
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>
メモ:
多くのブラウザーのユーザーエージェントスタイルシートでは、 :-webkit-autofill
スタイル定義に !important
を使用しており、 JavaScript によるハックで解決しない限り、ウェブページから上書きすることができません。例えば、 Chrome では内部スタイルシートで次のようになっています。
css
background-color: rgb(232, 240, 254) !important;
background-image: none !important;
color: -internal-light-dark(black, white) !important;
これは、 background-color
, background-image
, color
に独自のルールを設定できないことを意味します。
構文
:autofill
例
次の例は、 :autofill
擬似クラスを使用して、ブラウザーによって自動補完されたテキストフィールドの境界線を変更することを示しています。ブラウザーの互換性を保つために、 :-webkit-autofill
と :autofill
の両方を使用してください。
css
input {
border: 3px solid grey;
border-radius: 3px;
}
input:-webkit-autofill {
border: 3px solid blue;
}
input:autofill {
border: 3px solid blue;
}
html
<form method="post" action="">
<label for="email">Email</label>
<input type="email" name="email" id="email" autocomplete="email" />
</form>
仕様書
Specification |
---|
HTML # selector-autofill |
Selectors Level 4 # selectordef-autofill |
ブラウザーの互換性
関連情報
- 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 - new css4-ui features - more selectors