CSS optional Selector Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report The: optional selector in CSS is used to select and style the form input elements which are optional. That is it can select those input elements from an HTML form that are not declared as "required". Syntax::optional { /* css declarations; */}Example: HTML <!DOCTYPE html> <html> <head> <title>optional Selector</title> <style> /* Select optional fields and change color to Yellow */ input:optional { background-color: yellow; } h1 { color: green; } h1, h2 { text-align: center; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h3>A demonstration of the :optional selector.</h3> <!-- Create an HTML form --> <form> <!-- Optional Input --> <label>An optional input element:</label><br /> <input> <br /><br /> <!-- Required Input --> <label>A required input element:</label><br /> <input required> </form> <p> The :optional selector selects form elements with no "required" attribute. </p> </body> </html> Output: Supported Browser: Google Chrome 10.0Edge 12.0Firefox 4.0Safari 5.0Opera 10.0 Create Quiz Comment V vt_m Follow 1 Improve V vt_m Follow 1 Improve Article Tags : Web Technologies CSS CSS-Selectors Explore CSS Introduction 3 min read CSS Syntax 3 min read CSS Selectors 6 min read CSS Comments 2 min read CSS Colors 5 min read CSS Borders 5 min read CSS Margins 4 min read CSS Height and Width 4 min read CSS Outline 4 min read CSS Fonts 4 min read Like