:only-of-type CSS Pseudo Class

Description

The :only-of-type pseudo-class is applied to the child of the specified type only if it is unique to the parent.

Syntax

element :only-of-type { ... } 

Example

<main>
<div>I am 'div' #1.</div>
<p>I am the only 'p' among my siblings.</p>
<div>I am 'div' #2.</div>
<div>I am 'div' #3.
<i>I am the only 'i' child.</i>
<em>I am 'em' #1.</em>
<em>I am 'em' #2.</em>
</div>
</main>
main :only-of-type {
color: red;
}

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
91213.59.53.2
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
218410.13.2X