CSS Portal

:user-valid CSS Pseudo Class

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

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:

  1. The element is a form control that supports validation (such as an input).
  2. The user has interacted with the field (for example, typing or changing its value).
  3. 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

 <div class="field-group">
<label for="email">Email Address:</label>
<input
type="email"
id="email"
name="email"
required
placeholder="e.g. hello@example.com"
>
<span class="message">Success! That looks like a valid email.</span>
</div>

<button type="submit">Submit</button>
/* Initial styling for the input */
input {
border: 2px solid #ccc;
border-radius: 4px;
padding: 8px;
outline: none;
display: block;
margin-bottom: 5px;
}

/* Hide the success message by default */
.message {
display: none;
font-size: 0.8rem;
color: #2e7d32;
}

/* :user-valid triggers ONLY after:
1. The user interacts with the field.
2. The input matches the requirements (e.g., valid email format).
3. The user clicks away (blur).
*/
input:user-valid {
border-color: #2e7d32;
background-color: #e8f5e9;
}

/* Show the message only when the input is user-valid */
input:user-valid + .message {
display: block;
}

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
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 31st December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!