CSS :required Pseudo-class
Example
Select and style any <input> element with a "required" attribute. Also style any <input> element without a "required" attribute
input:optional {
background-color: lightgreen;
}
input:required {
background-color: pink;
border-color:
red;
}
Try it Yourself »
Definition and Usage
The :required
pseudo-class is used to select
and style required form elements (only for <input>, <select> and <textarea>).
Form elements with a "required" attribute are defined as required.
Tip: Use the :optional pseudo-class to select optional form elements.
Version: | CSS3 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the pseudo-class.
Pseudo-class | |||||
---|---|---|---|---|---|
:required | 10 | 10 | 4 | 5 | 10 |
CSS Syntax
:required {
css declarations;
}
Related Pages
CSS Reference :optional