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.
:valid
See :invalid for an example.
| 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. |
| Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 10 | 12 | 4 | 10 | 10 | 5 |
| Applies to <form> elements | Yes | No | 13 | No | Yes | ? |
| Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
|---|---|---|---|---|---|---|---|
| Basic support | ? | ? | Yes | 4 | 10 | 5 | ? |
| Applies to <form> elements | ? | ? | No | 14 | ? | ? | ? |
:required, :optional, :invalid
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/:valid