The only-of-type pseudo-class

The only-of-type pseudo-class selects an element that is the only child of a given type.

Syntax

cssselector:only-of-type {
  
}

Example

Let's color the h2 heading red if it is the only h2 in its parent:

html<div>
  <h2>header</h2>
  <p>paragraph</p>
  <p>paragraph</p>
  <p>paragraph</p>
</div>
<div>
  <h2>header</h2>
  <p>paragraph</p>
  
  <h2>header</h2>
  <p>paragraph</p>
  <p>paragraph</p>
</div>
cssdiv {
  border: 1px dashed black;
  padding: 15px;
  margin-bottom: 10px;
}
h2:only-of-type {
  color: red;
}

Результат: