:required - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:required

Description

The :required selector selects required form elements, who have the required attribute.

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

Example

Select only if the <input> element has a "required" attribute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
input:required {<!--  w  ww .ja va2 s  .c om-->
    background-color: yellow;
}
</style>
</head>
<body>

<input type='text'>

<input required>

</body>
</html>

Related Tutorials