CSS :user-invalid Pseudo-Class

Beginner
2 examples
Updated: Nov 2026

Definition and Usage

The :user-invalid pseudo-class matches a control that is invalid after user interaction. It prevents showing error styles before the user has tried to fill the field.

CSS Syntax

syntax.css
input:user-invalid {
  border-color: #dc2626;
}

Key Uses

PatternPurposeTry it
:user-invalidInvalid after user interactionTry it
vs :invalid:invalid can style untouched required fieldsTry it

CSS Examples

Error after interaction

example.css
input:user-invalid {
  border-color: #dc2626;
}
Try It Yourself

Browser Support

:user-invalid is a CSS selector.

✓ Selectors

:user-invalid

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
:user-invalid Modern support

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

Frequently Asked Questions

:invalid often matches empty required fields immediately, which feels noisy.
After the user interacts with the control and the value fails constraints.
Yes. Keep focus rings clear even when showing an error color.
Use :user-valid for the success state after interaction.
Supported in modern Chromium, Firefox, and Safari.

Next: :modal

Continue with :modal.

:modal →

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