CSS :autofill Pseudo-Class

Beginner
2 examples
Updated: Nov 2026

Definition and Usage

The :autofill pseudo-class matches form controls filled by the browser’s autofill feature. Use it to keep autofilled fields on-brand.

CSS Syntax

syntax.css
input:autofill {
  box-shadow: 0 0 0 1000px #ecfeff inset;
}

Key Uses

PatternPurposeTry it
:autofillMatches autofilled controlsTry it
inset shadow trickOverride the browser paint with a large inset shadowTry it

CSS Examples

Brand autofill background

example.css
input:autofill {
  box-shadow: 0 0 0 1000px #ecfeff inset;
  -webkit-text-fill-color: #0f172a;
}
Try It Yourself

Browser Support

:autofill is a CSS selector.

✓ Selectors

:autofill

Supported in modern browsers.

94% Modern browsers
Google Chrome Recent
Full support
Mozilla Firefox Recent
Full support
Apple Safari Recent
Full support
Microsoft Edge Recent
Full support
:autofill Modern support

Bottom line: Safe for modern sites. Keep readable defaults without the selector.

Frequently Asked Questions

Browsers apply their own autofill styling. :autofill lets you restyle them.
Some engines still expose :-webkit-autofill. Include both when needed.
Limited. Prefer solid colors and text fill overrides.
No. It only matches browser autofill.
Supported in Chromium and Safari; Firefox support depends on version.

Next: :user-valid

Continue with :user-valid.

:user-valid →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

2 people found this page helpful