# :user-invalid

> The `:user-invalid` CSS pseudo-class selects a form field with invalid value after the user has interacted with it.

## How do I show form errors only after the user interacts?

The pseudo-class that matches a form element with an invalid value only after the user has interacted with it or tried to submit the form. Unlike `:invalid`, it does not mark empty required fields as errors before the user touches them.

- Topic: Pseudo Classes
- Type: pseudo-class
- Browser support: Chrome 119+, Chrome Android 119+, Edge 119+, Firefox 88+, Firefox Android 88+, Safari 16.5+, Safari iOS 16.5+

## Example

Wrong:

```css
input:invalid {
  border-color: red;
}
```

Right:

```css
input:user-invalid {
  border-color: red;
}
```

`:user-invalid` waits until the user interacts or submits, so empty required fields aren't red on load.

## Common mistakes

- Using `:invalid`, which marks empty required fields red before the user types.

## Key points

- Error styles use `:user-invalid` instead of `:invalid`, so required fields aren't red on page load.
- Errors are also shown as text, not only by a red border.
- No JavaScript blur tracking class is added for the same effect.

## Interview questions

### What is the difference between :invalid and :user-invalid?

`:invalid` matches as soon as the value breaks a constraint, even on load. `:user-invalid` matches only after the user has interacted with the field or tried to submit.

### How do I show an error message with :user-invalid?

Place the message after the input and reveal it with a sibling selector, like `input:user-invalid + .error`, and link it with `aria-describedby`.

## Related cards

- [:user-valid](https://wonderium.dev/css/user-valid.md)
- [:invalid](https://wonderium.dev/css/invalid.md)
- [\[aria-invalid\]](https://wonderium.dev/a11y/aria-invalid.md)
- [Accessible Forms](https://wonderium.dev/a11y/accessible-forms.md)
- [`<input>`](https://wonderium.dev/html/input.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/user-invalid
- Last updated: 2026-11-25
