CSS :only-of-type Pseudo-class

Definition and Usage

CSS :only-of-type The pseudo-class is used to match any element that is the only child of its parent element and of the same type.

Example

Specify styles for any <p>, <li>, and <b> element that is the only child of its parent element and of the same type:

p:only-of-type {
  background-color: red;
{}
li:only-of-type {
  color: salmon;
{}
b:only-of-type {
  color: green;
{}

Try It Yourself

CSS Syntax

:only-of-type {
  css declarations;
{}

Technical Details

Version: CSS3

Browser Support

The numbers in the table specify the first browser version that fully supports this pseudo-class.

Chrome Edge Firefox Safari Opera
4.0 9.0 3.5 3.2 9.6