CSS Reference ยท Pseudo-classes
The :user-valid pseudo-class
Reference for the CSS :user-valid pseudo-class: match valid form controls only after the user has interacted with them, avoiding premature success styling.
The :user-valid pseudo-class matches a form control that passes validation and that the user has interacted with. Unlike :valid, it stays quiet on a freshly loaded form and only reacts after the user has edited the field and moved on, or tried to submit the form.
The exact moment the "interacted" flag turns on is up to the browser; commonly it is when the control loses focus after a change, or when the form is submitted.
input:user-valid { border-color: #16a34a; }
Try it
Syntax
:user-valid { /* declarations */ }
- Applies to: form controls that take part in constraint validation.
- Specificity: (0,1,0).
- Inherited / animatable: not applicable.
Values
| Syntax and arguments | Description |
|---|---|
:user-valid |
No arguments. Matches a validated control that is valid and has been interacted with by the user. |
Usage notes
- Better feedback timing. Use
:user-validfor success marks and:user-invalidfor errors, so users are not scolded before they type. - Not scriptable. Setting
.valuefrom JavaScript does not count as user interaction. - Layer it. Without support, a rule such as
input:user-validis dropped. Because browsers drop a whole selector list if one part is unknown, write separate rules rather thaninput:valid, input:user-valid. - No form-level match in older browsers. Do not depend on
form:user-valid; test the browsers you support. - Accessibility. Success states don't need loud announcements. A subtle icon plus text is enough.
Browser support
Supported in current Chrome, Edge, Safari and Firefox (Firefox earlier used the prefixed :-moz-ui-valid); it is relatively new, so older browsers ignore it.
Related
:user-invalid:valid:invalid- Lesson: Styling Forms