optional pseudo-class
The optional pseudo-class specifies
the style of an input that does not have
the required attribute specified,
i.e. this pseudo-class applies to optional
inputs.
Syntax
selector:optional {
}
Example
Let's give the optional input a gray background:
<form>
<p>
<label>Enter number</label>
<input type="number" required>
</p>
<p>
<label>Enter text</label>
<input type="text">
</p>
</form>
input:optional {
background-color: #D8DFE8;
}
:
See also
-
the
:defaultpseudo-class
that sets a default style for elements -
the
:indeterminatepseudo-class
that styles switches that are in an indeterminate state -
the
:placeholder-shownpseudo-class
that sets a style for elements when displaying tooltip text -
the
:read-onlypseudo-class
that sets a style for inputs that cannot be changed -
the
:requiredpseudo-class
that sets a style of the input that has the required attribute set -
the
:focus-withinpseudo-class
that styles the elements in focus -
the
caret-colorproperty
that sets a color of the text cursor in input