The :optional
selector selects form elements with no required
attribute.
The :optional
selector only applies to the form
elements: input
, select
and textarea
.
We can use the :required
selector to select form elements which are required.
:optional { style properties }
:optional |
Yes | 10.0 | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<head>
<style>
input:optional {<!-- ww w . j a v a 2s. com-->
background-color: red;
}
</style>
</head>
<body>
<p>An optional input element:<br><input></p>
<p>A required input element:<br><input required></p>
</body>
</html>