 Online: 22749
 Online: 22749
                
            By using optional selector we can give style to the input elements which does not have required attribute. The optional selectors selects form elements which are optional and applies the style to it.
<style> input:optional { background-color: lightblue; border-color: red; } </style> <body> <form> First Name<input type="text" required="required" />*<br/> Middle Name<input type="text" placeholder="This is Optional" /><br/> Last Name<input type="text" required="required" />* </form> </body>
In the above code snippet we have given style to the optional selector. So that the optional selector finds the <input> element which does not have required attribute and applies style to it.
OUTPUT