English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules

Complete List of CSS Attributes

CSS :required selector

Complete CSS Selector Reference Manual

Online Example

If the input element is set to "required", set it to red:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title> 
<style>
input:required
{
    background-color: red;
}
</style>
</head>
<body>
<h3>:required selector demonstration.</h3>
<p>Optional input elements:<br> <input> </p>
<p>Required input elements:<br> <input required> </p>
<p> :required selector selects form elements with the 'required' attribute.</p>
</body>
</html>
Test to see ‹/›

Definition and Usage

:required selector sets the specified style when the form element is a required field.

Form elements can use the required attribute to set required fields.

Note:  :required selector is only applicable to form elements: input, select, and textarea.

Browser Compatibility

The numbers in the table indicate the first browser version that supports this attribute.

Selector




:required10.010.04.05.010.0

Related Pages

CSS Selector :optional

Complete CSS Selector Reference Manual