:only-of-type

:only-of-type – pseudo-class | Selectors Level 3

The :only-of-type matches element that is only child of its parent element of given type.

Syntax

element:only-of-type{
    style properties
}

Example

The HTML code

<div>
    <ul>
        <li>1</li>
        <li>2</li>
    </ul>
    <p>Paragraph</p>
    <div>I am a div.</div>
</div>
p:only-of-type{
    background:#FFB7C5;
}

The paragraph p is selected because it is the only one in the parent element.

  • 1
  • 2

Paragraph

I am a div.

Related

Resources

Browser compatibility

:only-of-type

Internet Explorer
9,0
Firefox
3.5
Chrome
1.0
Safari
3.2
Opera
9.5
Mobile
Safari Mobile
works
Android
works
Chrome Mobile
works
IE Phone
works
Opera Mini
works
Opera Mobile
works