:user-valid CSS Pseudo Class
Description
The :user-valid pseudo-class represents a form control element that the user has interacted with and whose current value successfully passes validation constraints. Unlike the standard validation pseudo-classes, this one only becomes active after the user has provided input, making it especially useful for user-friendly feedback that avoids showing validation states too early.
What :user-valid does
The :user-valid pseudo-class applies when all of the following are true:
- The element is a form control that supports validation (such as an
input). - The user has interacted with the field (for example, typing or changing its value).
- The value satisfies all validation rules (e.g.,
required,pattern,type,min,max).
This makes it different from :valid, which may apply before any user interaction, depending on browser behavior and default values.
Why use :user-valid?
It helps create better UX by:
- Avoiding “green success” styling on untouched fields
- Showing validation feedback only when the user actually engages
- Preventing confusion during form completion
It pairs naturally with :user-invalid to create clean, responsive form validation states.
Basic example
<form>
<label>
Email:
<input type="email" required>
</label>
</form>
input:user-valid {
border-color: green;
background-color: #f0fff4;
}
In this example, the input will only turn green after the user enters a valid email address.
Comparison with :valid
| Pseudo-class | When it activates |
|---|---|
:valid |
When the value meets validation rules (even without user interaction) |
:user-valid |
Only after the user interacts and the value is valid |
This makes :user-valid ideal for modern form UX patterns.
Practical example with feedback text
<label>
Username:
<input type="text" required minlength="3">
<span class="status">Looks good!</span>
</label>
.status {
display: none;
color: green;
}
input:user-valid + .status {
display: inline;
}
The message appears only after the user enters a valid username.
Syntax
:user-valid {
/* ... */
}
Example
Browser Support
The following information will show you the current browser support for the CSS :user-valid pseudo class. Hover over a browser icon to see the version that first introduced support for this CSS psuedo class.
This psuedo class is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 31st December 2025
