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