JavaScript Mapping Library
A decade ago HTML and CSS added the ability to, at least signal, validation of form fields. The required attribute helped inform users which fields were required, while pattern allowed developers to provide a regular expression to match against an <input>‘s value. Targeting required fields and validation values with just CSS and HTML was very useful.
required
pattern
<input>
Did you know that CSS provides :optional to allow you to style form elements that aren’t required?
:optional
input:optional, select:optional, textarea:optional { border: 1px solid #eee; } [required] { border: 1px solid red; }
In a sense, it feels like :optional represents :not([required]), but :optional is limited to just form fields.
:not([required])
The post CSS :optional appeared first on David Walsh Blog.
David Walsh Blog
You must be logged in to post a comment.
This site uses Akismet to reduce spam. Learn how your comment data is processed.