CSS :required Selector


Example

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

input:required {
  background-color: yellow;
}
Try it Yourself »

Definition and Usage

The :required selector selects form elements which are required.

Form elements with a required attribute are defined as required.

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

Tip: Use the :optional selector to select form elements which are optional.

Version: CSS3

Browser Support

The numbers in the table specifies the first browser version that fully supports the selector.

Selector
:required 10.0 10.0 4.0 5.0 10.0

CSS Syntax

:required {
  css declarations;
}

Related Pages

CSS Selector :optional


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.