Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS :required selector

CSS :required selector

Complete CSS Selector Reference Manual Complete CSS Selector Reference Manual

Example

If an input element has the "required" attribute set, set it to yellow:

input:required

{

background-color: yellow;

}

Try it »


Definition and usage

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

Form elements can use the required attribute to set a required field.

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


Browser support

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

Selector
:required 10.0 10.0 4.0 5.0 10.0

CSS Syntax

:required

{

css declaration

;

}


Related pages

CSS selector :optional


Complete CSS Selector Reference Manual Complete CSS Selector Reference Manual