The required pseudo-class
The required
pseudo-class specifies
the style of the input that has the
required
attribute, i.e. this
pseudo-class applies to required inputs.
Syntax
selector:required {}
Example
Let's give the required input a blue background:
<form>
<p>
<label>Enter number</label>
<input type="number" required>
</p>
<p>
<label>Enter text</label>
<input type="text">
</p>
</form>
input:required {
background-color: #C2DDFD;
}
:
See also
-
the
:optional
pseudo-class
that sets a style for the input that does not have a required attribute -
the
:default
pseudo-class
that sets a default style for elements -
the
:indeterminate
pseudo-class
that styles switches that are in an indeterminate state -
the
:read-only
pseudo-class
that sets a style for inputs that cannot be changed -
the
:read-write
pseudo-class
that sets a style of the inputs available for change