:only-child (CSS selector)

Browser support (more…)
IE8 FF3+ SA3.1+ OP9.5+ CH2+
None Full Full Full Full


:only-child {
declaration block


This pseudo-class matches an element if it’s the only child element of its parent.


The following selector will match a list item element if it’s the only list item in its parent ol or ul element:

li:only-child {
  ⋮ declarations


Internet Explorer Firefox Safari Opera Chrome
5.5 6.0 7.0 8.0 1.0 1.5 2.0 3.0 3.5 1.3 2.0 3.1 4.0 9.2 9.5 10.0 2.0
None None None None None Buggy Buggy Full Full Buggy Buggy Full Full None Full Full Full

In Firefox 1.5 and 2, this selector will continue to match an element even after sibling elements are inserted dynamically before or after it.

In Safari versions up to and including 3, this selector behaves exactly like :first-child.

User-contributed notes

There are no comments yet.

Related Products