:optional - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:optional

Description

The :optional selector selects optional form elements, who do not have required attribute.

The :optional selector only applies to the form elements: input, select and textarea.

Example

Select if the <input> element does not have a "required" attribute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
input:optional {<!--from www  .j a v a2s  . c  om-->
    background-color: yellow;
}
</style>
</head>
<body>

<input type='text'>

<br><input  type='text' required>

</body>
</html>

Related Tutorials