The :first-child selector matches every element that is the first child of its parent. Unlike .first(), it can return multiple nodes — one per parent. Standard CSS since jQuery 1.1.4; equivalent to :nth-child(1).
01
Syntax
span:first-child
02
Per parent
Many matches
03
Official
div span
04
vs .first()
One global
05
nth(1)
Equivalent
06
CSS
Standard
Fundamentals
Introduction
Layout patterns often treat the first item in a group differently — bold the lead nav link, underline the opening name in a list, or highlight the first column in a table. The CSS :first-child pseudo-class selects those elements based on sibling position within each parent.
jQuery supports :first-child in selector strings since version 1.1.4. Official documentation emphasizes that while .first() matches only a single element, :first-child can match more than one — one for each parent in the document.
Concept
Understanding the :first-child Selector
Think of :first-child as “the first sibling under each parent”:
<div><span>A</span><span>B</span></div> → first span matches span:first-child.
Second <div> with its own first span → also matches.
<div><p>…</p><span>…</span></div> → span is not first child — no match for span:first-child.
Equivalent to :nth-child(1) per official jQuery docs.
💡
Beginner Tip
Need only the very first element in a flat list? Use $("li").first(). Need the first item in every list? Use $("ul li:first-child").
Sibling position per parent vs global index in a matched set.
:first-child
li:first-child
First per parent
.first()
$("li").first()
One element total
:nth-child(1)
p:nth-child(1)
Equivalent
:eq(0)
li:eq(0)
0-based set index
Hands-On
Examples Gallery
Example 1 follows the official jQuery div span:first-child demo. Examples 2–5 contrast with .first(), style navigation lists, verify :nth-child(1), and highlight table columns.
📚 Official jQuery Demo
Underline the first span in each div with a hover class toggle.
Example 1 — Official Demo: div span:first-child
Official jQuery demo — John and Glen underlined; hover adds green bold styling.
Name, Ada, Ben columns (first td per row) → gray + bold
Age and City columns → unchanged
How It Works
Each tr is a parent — the first td in every row matches, including the header row.
Applications
🚀 Common Use Cases
Navigation — style li:first-child as the home or primary link.
Inline name lists — official demo pattern with span:first-child.
Tables — highlight td:first-child label columns.
Card grids — remove left margin on .card:first-child per row wrapper.
Form rows — bold labels that are the first child in a field group.
CSS parity — same selector works in stylesheets and jQuery.
🧠 How jQuery Evaluates :first-child
1
Parse selector
Combine type selector with :first-child — e.g. div span:first-child.
Query
2
Check parent
For each candidate, verify it is the first element child of its parent.
CSS
3
Collect matches
One match per parent — can be many elements document-wide.
Set
4
✓
Return collection
Chain .css(), .hover(), or other jQuery methods.
Important
📝 Notes
Available since jQuery 1.1.4 — standard CSS pseudo-class.
Equivalent to :nth-child(1) — official jQuery documentation.
Can match multiple elements — unlike .first() which returns one.
Element must be the first child of its parent — preceding siblings block a match.
Works in native querySelectorAll — no jQuery extension caveat.
Not the same as :first-of-type — that ignores siblings of other tag names.
Compatibility
Browser Support
The :first-child pseudo-class is standard CSS and works in jQuery 1.1.4+. All modern browsers support document.querySelectorAll("li:first-child"). Same syntax in stylesheets and jQuery selectors.
Bottom line: Use li:first-child or div span:first-child — scope to parents; prefer over bare :first-child.
Wrap Up
Conclusion
The :first-child selector matches every element that is the first child of its parent — the official div span:first-child demo underlines John and Glen, not the other spans.
Distinguish it from .first() and :eq(0), remember equivalence with :nth-child(1), and scope your selector to the parents you care about.
Choose :first-child when every parent needs a first item styled
Use .first() when you need one global match
Remember :nth-child(1) is equivalent
Reuse the same selector in CSS and jQuery
❌ Don’t
Confuse :first-child with :first-of-type without reading docs
Assume the first element in document order — check parent context
Use bare $(":first-child") on large pages
Expect a match when a different element is the first child
Replace :first-child with :eq(0) — different indexing models
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :first-child
First child of each parent.
5
Core concepts
1st01
:first-child
Per parent
API
n02
Many
Not .first()
Rule
nth03
nth(1)
Equivalent
CSS
demo04
Official
span hover
Demo
CSS05
Standard
Native CSS
Tip
❓ Frequently Asked Questions
:first-child selects every element that is the first child of its parent. $("div span:first-child") matches the first span inside each div — so multiple elements can match. Available since jQuery 1.1.4.
.first() returns only one element — the first in the entire jQuery matched set. :first-child can return many — one per parent. Official docs highlight this distinction explicitly.
Yes. Official jQuery documentation states that :first-child is equivalent to :nth-child(1). Both select elements that are the first child of their parent (1-based child index in CSS).
Yes. :first-child is standard CSS and works in native querySelectorAll — e.g. document.querySelectorAll("li:first-child"). jQuery has supported it since 1.1.4.
If a text node or comment appears before the element, or if another element is the first child, your target will not match. :first-child checks sibling position among all child nodes of the same type rules in CSS — only element siblings count for :first-child among elements of that selector.
Yes — $("li:first-child") or $("div span:first-child") is clearer than bare $(":first-child"). Scoping to a parent class or ID avoids matching unintended first children across the page.
Did you know?
:first-child and :first-of-type differ when siblings of other element types come first. If a <p> precedes a <span>, the span is not :first-child but may still be :first-of-type among spans.