{"id":14246,"date":"2011-09-06T20:26:20","date_gmt":"2011-09-07T03:26:20","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=14246"},"modified":"2021-08-04T10:30:22","modified_gmt":"2021-08-04T17:30:22","slug":"optional","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/selectors\/o\/optional\/","title":{"rendered":":optional"},"content":{"rendered":"\n

The :optional<\/code> pseudo class targets inputs (including <select><\/code>s) that are not specifically set as required<\/code> (do not have the required<\/code> attribute).<\/p>\n\n\n\n

This can be useful when you want to give optional fields a specific look, maybe slightly less visible than required ones.<\/p>\n\n\n

<\/a>Syntax<\/h3>\n\n\n
input[type=text]:optional {\n  border: 1px solid #eee;\n}<\/code><\/pre>\n\n\n

<\/a>Demo<\/h3>\n\n\n

In the following demo, optional field (\u201cName\u201d, \u201cGender\u201d and \u201cContinent\u201d) have their opacity lowered to 40% so users can immediately know what are the required fields. In this case, \u201cEmail\u201d. When hovered, an optional input will see the opacity go back to 100%.<\/p>\n\n\n\n

The\u00a0optional<\/code>\u00a0works on all type of form elements: text inputs of all types, radio buttons, checkboxes, and selects.<\/p>\n\n\n\n