The :first-of-type selector matches every element that is the first of its tag name among siblings. It can return multiple nodes — one per parent. Standard CSS since jQuery 1.9; equivalent to :nth-of-type(1).
01
Syntax
span:first-of-type
02
Per parent
Many matches
03
Official
span + fot
04
vs :first-child
Tag-based
05
nth-of-type
Equivalent
06
CSS
Standard
Fundamentals
Introduction
Real markup mixes element types — a paragraph intro, then spans, then more paragraphs. You often need the first <p> or first <span> in each block, even when another tag is the overall first child. The CSS :first-of-type pseudo-class selects by element name among siblings, not absolute child position.
jQuery supports :first-of-type in selector strings since version 1.9. Official documentation states that it matches elements with no other element of the same name and parent coming before them in the document tree — so $("span:first-of-type") can match many spans, one per parent.
Concept
Understanding the :first-of-type Selector
Think of :first-of-type as “the first sibling of this tag name under each parent”:
<div><span>A</span><span>B</span></div> → first span matches span:first-of-type.
Second <div> with its own first span → also matches.
<div><p>…</p><span>…</span></div> → span matches span:first-of-type but not span:first-child.
Equivalent to :nth-of-type(1) in standard CSS.
💡
Beginner Tip
When siblings are all the same tag (e.g. only <li> in a list), :first-of-type and :first-child behave the same. They diverge when mixed element types share a parent.
No arguments — matches elements that are the first of their element type among siblings.
Return value
A jQuery object containing every matching first-of-type element (often multiple).
Empty collection when no element is first-of-type in scope.
Official jQuery API example
jQuery
$( "span:first-of-type" ).addClass( "fot" );
Cheat Sheet
⚡ Quick Reference
Goal
:first-of-type
:first-child
First span in each div
span:first-of-type
Same if span is first child
Span after a <p> sibling
Matches
No match
First paragraph in article
article p:first-of-type
Only if p is first child
Equivalent pseudo-class
:nth-of-type(1)
:nth-child(1)
Native CSS
Supported
Supported
Compare
📋 :first-of-type vs :first-child and :nth-of-type(1)
Tag-based sibling position vs absolute first child vs typed nth index.
:first-of-type
span:first-of-type
First span per parent
:first-child
span:first-child
Must be first child
:nth-of-type(1)
p:nth-of-type(1)
Equivalent
Mixed markup
p then span
Only :first-of-type
Hands-On
Examples Gallery
Example 1 follows the official jQuery span:first-of-type demo. Examples 2–5 contrast with :first-child, style article lead paragraphs, verify :nth-of-type(1), and highlight table columns.
📚 Official jQuery Demo
Add the fot class to the first span in each matched div.
Example 1 — Official Demo: span:first-of-type
Official jQuery demo — Corey and Nobody styled red, italic, and larger; other spans unchanged.
Definition lists — style the first dt or dd in each group.
CSS parity — same selector works in stylesheets and jQuery.
🧠 How jQuery Evaluates :first-of-type
1
Parse selector
Combine type selector with :first-of-type — e.g. span:first-of-type.
Query
2
Check siblings
For each candidate, verify no same-tag sibling appears earlier under the same parent.
CSS
3
Collect matches
One match per parent per tag — can be many elements document-wide.
Set
4
✓
Return collection
Chain .addClass(), .css(), or other jQuery methods.
Important
📝 Notes
Available since jQuery 1.9 — standard CSS pseudo-class.
Equivalent to :nth-of-type(1) — standard CSS specification.
Can match multiple elements — one first-of-type per parent for the chosen tag.
Differs from :first-child when siblings of other element types precede the target.
Works in native querySelectorAll — no jQuery extension caveat.
Always pair with an element type — p:first-of-type, not bare :first-of-type on large pages.
Compatibility
Browser Support
The :first-of-type pseudo-class is standard CSS and works in jQuery 1.9+. All modern browsers support document.querySelectorAll("p:first-of-type"). Same syntax in stylesheets and jQuery selectors.
Bottom line: Use p:first-of-type or article p:first-of-type — scope to parents; prefer over bare :first-of-type.
Wrap Up
Conclusion
The :first-of-type selector matches every element that is the first of its tag name among siblings — the official span:first-of-type demo styles Corey and Nobody with the fot class, not the other spans.
Distinguish it from :first-child, remember equivalence with :nth-of-type(1), and scope your selector to the parents you care about.
Use article p:first-of-type for scoped lead paragraphs
Choose :first-of-type when mixed sibling tags break :first-child
Remember :nth-of-type(1) is equivalent
Reuse the same selector in CSS and jQuery
Compare with :first-child when debugging unexpected matches
❌ Don’t
Assume :first-of-type equals :first-child without checking markup
Use bare $(":first-of-type") on large pages
Confuse :nth-of-type with :nth-child — different counting rules
Expect a match when an earlier same-tag sibling exists
Forget to scope — prefix with a parent selector when possible
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :first-of-type
First of each tag name per parent.
5
Core concepts
1st01
:first-of-type
Per tag per parent
API
≠02
Not :first-child
Mixed tags differ
Rule
nth03
nth-of-type(1)
Equivalent
CSS
demo04
Official
span + fot
Demo
CSS05
Standard
Native CSS
Tip
❓ Frequently Asked Questions
:first-of-type selects every element that is the first among siblings with the same element name (tag). $("span:first-of-type") matches the first span in each parent — Corey and Nobody in the official demo. Available since jQuery 1.9.
:first-child requires the element to be the first child of its parent among all element types. :first-of-type only compares siblings with the same tag. If a <p> comes before a <span>, the span is not :first-child but can still be span:first-of-type.
Yes. In CSS, :first-of-type is equivalent to :nth-of-type(1). Both select the first element of that tag name among siblings under the same parent.
Yes. :first-of-type is standard CSS and works in native querySelectorAll — e.g. document.querySelectorAll("p:first-of-type"). jQuery has supported it since 1.9.
Another element type may be the first child. Example: <div><p>Intro</p><span>Lead</span></div> — the span matches span:first-of-type but not span:first-child because the paragraph is the first child.
Yes — $("p:first-of-type") or $("article h2:first-of-type") is clearer than bare $(":first-of-type"). Scoping to a parent class or ID avoids matching unintended first-of-type nodes across the page.
Did you know?
:first-of-type looks at element names only — class names and IDs do not matter. Two <span class="a"> and <span class="b"> are both spans; only the first span among siblings matches span:first-of-type.