← Back to pseudo-classes
CSS Pseudo-class / Element
:optional
FormSelects form elements that do not have the required attribute.
Syntax
input:optional { }Example
input:optional { border-style: dashed; }Common use cases
- Visually distinguishing optional from required fields
- Styling optional inputs with a lighter border
- Improving form clarity for users
Practical developer insight
:optional is the counterpart of :required — it matches all inputs without the required attribute, which is most inputs by default.