CSS | : valid Selector
The :valid selector is used to select the form elements with a given value that validates according to the elements.
This selector only works for form elements with some limitations such as input elements with min and max attributes, email fields with a legal email, or number fields with a numeric value, etc.
Syntax:
:valid {
// CSS property
}
Example:
<!DOCTYPE html> <html> <head> <title>valid selector</title> <style> h1 { color:green; } input:valid { background-color: green; color:white; } body { text-align:center; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>:valid Selector</h2> Email Address: <input type="email" placeholder="abc@gfg.com"> </body> </html> |
Output:

Supported Browsers: The browser supported by :valid selector are listed below:
- Apple Safari 5.0
- Google Chrome 10.0
- Firefox 4.0
- Opera 10.0
- Internet Explorer 10.0
Recommended Posts:
- PHP | SplObjectStorage valid() Function
- PHP | SplFixedArray valid() Function
- Which characters are valid in CSS class names/selectors?
- JavaScript | Check if a string is a valid hex color representation
- CSS | ::before selector
- CSS | ::after Selector
- CSS | #id Selector
- CSS | :not Selector
- CSS | * Selector
- CSS | [attribute*=value] Selector
- CSS | :hover Selector
- CSS | [attribute^=value] Selector
- CSS | :nth-last-of-type() Selector
- CSS | [attribute$=value] Selector
- CSS | :nth-last-child() Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



