CSS :optional selector
Complete CSS Selector Reference Manual
Example
If an input element does not have the "required" attribute set, set it to yellow:
input:optional
{
background-color: yellow;
}
Try it »
Definition and usage
:optional selector sets a specified style when a form element is optional.
A form element without a specifically set required attribute is an optional element.
Note: The :optional selector only applies to form elements: input, select, and textarea.
Browser support
The numbers in the table indicate the first browser version that supports this property.
| Selector | |||||
|---|---|---|---|---|---|
| :optional | 10.0 | 10.0 | 4.0 | 5.0 | 10.0 |
CSS Syntax
:optional
{
css declaration
;
}
Related pages
CSS selector :required