CSS :optionalSelectors

Complete CSS Selector Reference Manual

Example

If the input element does not have the "required" attribute set, set it to yellow:

input:optional
{
background-color: yellow;
}

Try it Yourself »

Definition and use

The :optional selector sets the specified style when a form element is optional.

In form elements, if the required attribute is not specifically set, it is an optional attribute.

Note::optional selector only applies to form elements: input, select and textarea.


Browser Support

The numbers in the table indicate the first browser version number that supports the attribute.

Selectors
:optional 10.0 10.0 4.0 5.0 10.0

CSS Syntax

:optional
{
CSS Declaration;
}


Related Pages

CSS selectors:required


Complete CSS Selector Reference Manual

other extensions