Abakada: Back to Basics > Language References > CSS Properties > Pseudo-Classes > only-of-type Pseudo-class
Matches the only element of its type.
selector:only-of-type { property: value; }
property |
Any valid CSS property. |
value |
Any of the range of values available to the corresponding property. |
The :only-of-type pseudo-class applies styles to the only element that has no siblings of the same type.
The syntax for using the :only-of-type pseudo-class is straightforward. A selector immediately precedes the pseudo-class.
For example, to change the background color of only-of-type elements on a page.
div:only-of-type { background-color: beige }
The following demonstrates use of the :only-of-type pseudo-class in an embedded stylesheet to set the style of only-of-type elements on a page.
:first-of-type :last-of-type :nth-of-type( ) :nth-last-of-type( )