# only-child pseudo-class

The `only-child` pseudo-class selects an element that is the only child of its parent.

## Syntax

`selector:only-child { }`

## Example

In this example, we will make `li` red if it is the only child of the parent `ul`:

`<ul> <li>list item</li> </ul> <ul> <li>list item</li> <li>list item</li> <li>list item</li> </ul>` `li:only-child { color: red; } ul { margin-bottom: 10px; }`

:

← →
↑
en ru