:user-invalid
Widely availableSince 202394% of users
Matches input elements after the user has modified them and they are invalid. Shows validation errors to users.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyModernIn every major browser since November 2023. Widely available since May 2026.
The old way and the modern waySee the snippet: Form validation styles without JavaScript →
Old way 11 lines
/* only style after .touched class is added by JS */
input.touched:invalid {
border-color: red;
}
input.touched:valid {
border-color: green;
}
/* JS: add .touched class on blur */
input.addEventListener('blur', () => {
input.classList.add('touched');
});Modern 7 lines
input:user-invalid {
border-color: red;
}
input:user-valid {
border-color: green;
}
/* no JS, no .touched class */See how modern your own CSS is.Check your CSS →
Quick example
input:user-invalid { border-color: red; }
input:user-invalid::after { content: "✗"; }Examples
Show error state after user interaction
input:user-invalid {
border-color: red;
background-color: #ffebee;
}
/* Red border only after user tries to submit */Style invalid inputs only after the user has interacted, avoiding red errors on fresh forms.
Combine with validation feedback
.email-field:user-invalid::after {
content: "Invalid email";
color: red;
font-size: 0.9em;
}Show validation messages only after user interaction, not on page load.
Common pitfalls
- :user-invalid requires user interactionA field is :user-invalid only after the user has changed it. On page load, invalid fields don't match :user-invalid. Use :invalid to style all invalid inputs.
- Different from :invalid:invalid matches all invalid inputs; :user-invalid only matches those the user has touched. Choose based on UX: avoid red on load, but do show errors after user edits.
:user-invalid browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2023.Safe to use without fallbacks.
Usage94%of people can use this6% use a browser without it.
Browsers
119+
88+
16.5+
119+Mobile
119+Android
88+Android
16.5+iOS