The :required
CSS pseudo-class represents any <input>
, <select>
, or <textarea>
element that has the required
attribute set on it.
/* Selects any required <input> */ input:required { border: 1px dashed red; }
This pseudo-class is useful for highlighting fields that must have valid data before a form can be submitted.
Note: The :optional
pseudo-class selects optional form fields.