Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-classes

The :first-of-type pseudo-class

Reference for the CSS :first-of-type pseudo-class: select the first sibling with a given tag name, with syntax, examples, comparison with :first-child and support.

The :first-of-type pseudo-class matches an element that is the first among its siblings with the same tag name. In a parent holding a heading, three paragraphs and an image, p:first-of-type picks the first paragraph, even though it is not the first child.

That is the key difference from :first-child, which cares only about position, not tag.

CSS
p:first-of-type {
  font-size: 1.25rem;
}

Try it

Lead paragraph after a heading

Syntax

CSS
:first-of-type { /* declarations */ }

No arguments; specificity (0,1,0). Used alone (:first-of-type) it matches the first of each tag name in every parent.

Syntax and arguments

Part Description
:first-of-type Matches an element with no preceding sibling of the same element type.
No arguments The pseudo-class is not functional.
Equivalent :nth-of-type(1)
Type The tag name (and namespace); classes do not count.

Usage notes

  • Classes are ignored. p.note:first-of-type means "a p with class note that is also the first p among its siblings", not "the first .note". If the first p has no note class, nothing matches.
  • Different tags don't interfere. A <div> before your <p> does not stop p:first-of-type.
  • Typical uses. Lead paragraphs, removing margin from the first heading or figure in a block, and styling the first image in an article.
  • Parent matters. The count restarts inside every parent, so each section can have its own first paragraph.
  • Choosing the right tool. Use :first-child for "first thing in the box", :first-of-type for "first of this kind".

Browser support

Supported in every browser.