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

CSS Reference Manual

CSS @rules

Complete CSS Properties List

CSS3 :first-of-type selector

CSS pseudo-class :first-of-type represents the first element of its type in a group of sibling elements.

Complete CSS Selector Reference Manual

Online Example

The selected p element is the first p element of its parent element:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title> 
<style> 
/* Select the first <p> that appears in the parent element, regardless of its position among the siblings */
p:first-of-type {
  color: red;
}
</style>
</head>
<body>
<h1>This is a title</h1>
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<p>This is the third paragraph.</p>
<p>This is the fourth paragraph.</p>
</body>
</html>
Test and see ‹/›

Definition and Usage

:first-of-The type selector matches the first child element of a parent element that is of a specific type.

Tip: and :nth-of-type(1) means the same thing.

Browser Compatibility

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

Selector




:first-of-type4.09.03.53.29.6

Complete CSS Selector Reference Manual