English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Complete CSS Selector Reference Manual
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 ‹/›
: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.
The numbers in the table indicate the first browser version that supports this attribute.
Selector | |||||
---|---|---|---|---|---|
:required | 10.0 | 10.0 | 4.0 | 5.0 | 10.0 |
CSS Selector :optional