CSS :optional Selector

❮ Previous Selectors Next ❯

Example

input:optional { 
  background-color: yellow;
}

Meaning

The :optional selector selects <input> , <select>, or <textarea> element that does not have the required attribute set on it.

Use the :required selector to select form elements which are required.

This pseudo-class is useful for styling fields that are not required to submit a form.

Note: The :required pseudo-class selects required form fields.

This will ensure that people navigating with the aid of assistive technology such as a screen reader will be able to understand which inputs need valid content to ensure a successful form submission.

Version: CSS3




Standard Syntax

:optional {
  css declarations;
}



Browser Support

The numbers in the table specify the first browser version that fully supports the property.




Status







❮ Previous Selectors Next ❯