pseudo-class
:optional — CSS reference
Matches controls to which optionality applies and which are not required. It is not a universal negation of required.
Formal Syntax & Structure
css syntaxcss
:optionalWorking Example
Example Snippetcss
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Selector lab</title><style>:where(.sample) { color: rgb(32, 32, 32); }input:optional { color: rgb(0, 96, 80); }</style></head><body><label>A <input id="a" class="sample" value="ok"></label><label>B <input id="b" class="sample" required value="ok"></label></body></html>