English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
CSS pseudo-class :first-of-type represents the first element of its type in a group of sibling elements.
Complete CSS Selector Reference Manual
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 ‹/›
: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.
The numbers in the table indicate the first browser version that supports this attribute.
Selector | |||||
---|---|---|---|---|---|
:first-of-type | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |