Files
freeCodeCamp/guide/english/css/selectors/pseudo/optional/index.md

24 lines
558 B
Markdown
Raw Normal View History

---
title: Optional
---
## Optional
The CSS :optional selector changes the style of an input element if the `required` tag is not used.
The :optional selector can be used on the input, select and textarea element
In the example below, the required field will be blue and the optional field red
```css
input {
background-color: blue;
}
input:optional {
background-color: red;
}
```
#### More Information:
* [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/CSS/:optional)
* [W3 Schools](https://www.w3schools.com/cssref/sel_optional.asp)