CSS :only-of-type Selector

❮ Previous Selectors Next ❯


/*sets the p element background color to be red if it is the only p tag child of its parent */
p:only-of-type {
  background: red;


The :only-of-type selector Selects an element if it’s the only child of its parent with its type.

Note: As originally defined, the selected element had to have a parent. Beginning with Selectors Level 4, this is no longer required.

Version: CSS3

Standard Syntax

:only-of-type {
  css declarations;

Browser Support

The numbers in the table specify the first browser version that fully supports the property.


❮ Previous Selectors Next ❯