---
title: "CSS :user-valid and :user-invalid for Friendlier Form Errors"
description: "The new pseudo-classes :user-valid and :user-invalid give us a smarter way to style form validation states based on user interaction"
canonical: "https://www.trevorlasn.com/blog/css-user-valid-and-user-invalid-pseudo-classes"
author: "Trevor I. Lasn"
published: "2024-12-12"
last-updated: "2026-11-08"
topics: ["CSS", "HTML"]
---

# CSS :user-valid and :user-invalid for Friendlier Form Errors

The new pseudo-classes :user-valid and :user-invalid give us a smarter way to style form validation states based on user interaction

By Trevor I. Lasn · Published 2024-12-12 · Updated 2026-11-08 · https://www.trevorlasn.com/blog/css-user-valid-and-user-invalid-pseudo-classes

Form validation styling has always been tricky to get right. The new `:user-valid` and `:user-invalid` pseudo-classes fix a long-standing frustration with CSS form validation - showing error states too early.

## Update: Now Baseline Widely Available

Since May 2026, `:user-valid` and `:user-invalid` are Baseline Widely available. They have worked in every major browser since November 2023: Chrome and Edge 119, Firefox 88 and Safari 16.5.

Use them without a fallback, and keep the `@supports` approach below only if you support browsers older than those. Source: [webstatus.dev](https://webstatus.dev/features/user-pseudos).

[Browser support for `user-pseudos` on webstatus.dev](https://webstatus.dev/features/user-pseudos)

Unlike their predecessors `:valid` and `:invalid`, these new selectors wait for meaningful user interaction before applying styles. This seemingly small difference leads to a significantly better user experience: **no more fields marked as invalid before users even start typing.**

```css title="CSS" del={1-7} ins={8-15}
/* old approach - shows immediately */
input:invalid {
  border-color: #ef4444;
}
input:valid {
  border-color: #10b981;
}
/* New approach - waits for user interaction */
input:user-invalid {
  border-color: #ef4444;
}

input:user-valid {
  border-color: #10b981;
}
```

With traditional validation, this input would show an error state immediately because it's empty and required. The new `:user-valid` and `:user-invalid` selectors only apply styles after meaningful interaction.

Forms now start neutral and validate naturally as people use them. No more angry red borders on page load - just clean, helpful feedback when it makes sense.

### Fallbacks and Browser Support
Browser support for these new selectors is still rolling out, but that's okay. Modern browsers get the improved behavior while older ones fall back to traditional validation - no JavaScript needed either way.

These pseudo-classes are nice, but what about browsers that don't support them yet? There's no built-in fallback - older browsers will simply ignore these selectors. This means users on those browsers won't see any validation styles at all.

For now, the safest approach is to use [@supports](https://www.trevorlasn.com/blog/detect-css-features-with-supports-property) to provide a fallback for browsers that don't support `:user-valid` and `:user-invalid`. This way, you can ensure that all users see some form of validation styling.

```css title="CSS"
/* Base styles for all browsers */
input:invalid {
  border-color: #ef4444;
}
input:valid {
  border-color: #10b981;
}

/* Enhanced styles for modern browsers */
@supports selector(:user-valid) {
  input:invalid {
    border-color: initial;
  }
  input:valid {
    border-color: initial;
  }
  
  input:user-invalid {
    border-color: #ef4444;
  }
  input:user-valid {
    border-color: #10b981;
  }
}
```

These small improvements in form validation show how CSS continues to evolve in the right direction.
