:user-invalid

A modern pseudo-class that targets form elements that are currently invalid, but ONLY after the user has interacted with them. This avoids showing scary red errors immediately before the user has even started typing.

Quick example

input:user-invalid {
  border-color: red;
  /* show error style only after user has finished typing and exited the field */
}

input:user-invalid + .error-msg {
  display: block;
}

:user-invalid Browser Support

Newly available Since 2023 87% global usage

Since 2023 this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Works in all modern browsers. May need a fallback for older browsers.

119+
88+
16.5+
119+
ESC