# :user-valid

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

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

The pseudo-class that matches a form element with a valid value only after the user has interacted with it. Unlike `:valid`, it does not apply styles immediately on page load, which makes form feedback less intrusive.

- 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.touched:valid {
  border-color: green;
}
```

Right:

```css
input:user-valid {
  border-color: green;
}
```

`:user-valid` tracks interaction itself, so no JavaScript class is needed to delay success styles.

## Common mistakes

- Showing a success mark on an optional field the user left empty, which still counts as valid.

## Key points

- Success styles use `:user-valid`, so untouched fields don't show as valid on load.
- Success is shown with an icon or text too, not only by green color.

## Interview questions

### When does :user-valid start matching?

After the user changes the value and commits it, for example by leaving the field, or after a submit attempt. Before that, it matches neither `:user-valid` nor `:user-invalid`.

### Does :user-valid match an empty optional field?

It can. An optional field the user clears and leaves is still valid, so add `:not(:placeholder-shown)` if success marks need a value.

## Related cards

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

---

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