Entry 07
Form feedback with :user-invalid
Use it for inline form validation, in place of blur listeners and a "touched" class.
Code
input:user-invalid { border-color: var(--danger); }
input:user-valid { border-color: var(--success); }<input type="password" required minlength="8">Why it works, the rules and the credits
Why it works
:invalidmatches an empty required field on page load. The:user-versions match only after the user has edited the field or tried to submit.- Validity comes from HTML attributes:
required,minlength,type,pattern.
Rules
- Color alone is not enough feedback. Pair it with text or an icon.
- The server still validates.
Support
- Chrome
- 119
- Firefox
- 88
- Safari
- 16.5
Credits
Borrowed from: Kevin Powell, Improve forms with :user-valid and :user-invalid, 2025-02-20, and Use these CSS features instead of JavaScript, 2026-09-23