English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules

Complete List of CSS Attributes

CSS3 :only-of-type Selector

CSS Pseudo-class :only-of-type represents any element that does not have other elements of the same type as siblings.

Complete CSS Selector Reference Manual

Online Example

Specify each p element that belongs to a specific type of unique child element of the parent element::

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title>
<style>
div {
  border: 1px solid #ccc;
  margin: 20px;
  padding: 10px 10px 10px 30px;
}
p:only-of-type {
  color: red;
}
</style>
</head>
<body>
<div>
  <p>I am the only paragraph element in this div.</p>  
  <ul>
    <li>List Item</li>
    <li>List Item</li>
  </ul>  
</div>
<div>
  <p>This div contains multiple paragraphs.</p>  
  <p>I am also a paragraph.</p>  
  <ul>
    <li>List Item</li>
    <li>List Item</li>
  </ul>  
</div>
</body>
</html>
Test See ‹/›

Definition and Usage

element:only-of-type { style properties }

:only-of-type represents any element that does not have other elements of the same type as siblings.

Browser Compatibility

The numbers in the table indicate the first browser version that supports this attribute.

Selector




:only-of-type4.09.03.53.29.6

Complete CSS Selector Reference Manual