The :valid
CSS pseudo-class represents any <input>
or other <form>
element whose contents validate successfully. This allows to easily make valid fields adopt an appearance that helps the user confirm that their data is formatted properly.
/* Selects any valid <input> */ input:valid { background-color: powderblue; }
This pseudo-class is useful for highlighting correct fields for the user.
Syntax
:valid
Examples
See :invalid
for an example.
Accessibility concerns
The color green is commonly used to indicate valid input. People who have certain types of color blindness will be unable to determine the input's state unless it is accompanied by an additional indicator that does not rely on color to convey meaning. Typically, descriptive text and/or an icon are used.
- MDN Understanding WCAG, Guideline 1.4 explanations
- Understanding Success Criterion 1.4.1 | W3C Understanding WCAG 2.0
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of ':valid' in that specification. |
Living Standard | No change. |
HTML5 The definition of ':valid' in that specification. |
Recommendation | Defines the semantics of HTML and constraint validation. |
Selectors Level 4 The definition of ':valid' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
:valid | Chrome Full support 10 | Edge Full support 12 | Firefox Full support 4 | IE Full support 10 | Opera Full support 10 | Safari Full support 5 | WebView Android Full support 37 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 5 | Samsung Internet Android Full support 1.0 |
Applies to <form> elements | Chrome Full support 40 | Edge No support No | Firefox Full support 13 | IE No support No | Opera Full support 27 | Safari Full support 9 | WebView Android Full support 40 | Chrome Android Full support 40 | Firefox Android Full support 14 | Opera Android Full support 27 | Safari iOS Full support 9 | Samsung Internet Android Full support 4.0 |
Legend
- Full support
- Full support
- No support
- No support
See also
- Other validation-related pseudo-classes:
:required
,:optional
,:invalid
- Form data validation
- Accessing the validity state from JavaScript