:first-child (since jQuery 1.1.4) selects every element that is the first child of its parent. Unlike .first(), which returns one element from a set, :first-child can match one per parent. It is equivalent to :nth-child(1).
Remember
// Official pattern — first span in each div
$("div span:first-child");
// First list item in each ul
$("ul li:first-child");
// Same as :nth-child(1)
$("p:nth-child(1)");
// Not the same as .first() (one element only)
$("li").first();
Scope the selector, then style or read the matched first children.
Write a typed selector such as $("li:first-child") or $("div span:first-child").
Optionally scope with a parent: $("ul.nav li:first-child").
Chain methods — .text(), .addClass(), events.
Remember: the element must be the first element child of its parent.
Use .first() only when you want one match from the whole set.
Piece
Required?
Role
Tag / filter
Recommended
e.g. li, span, td
:first-child
Yes
Must be the first element sibling
Parent scope
Optional
Limits which trees are searched
Pseudocode
Pseudocode
for each element matching the left side (e.g. span):
look at its parent
if this element is the first element child of that parent:
include it in the result
result may contain many elements
→ one match is possible for each parent
.compare with .first():
take the full matched set
keep only the first item in that set
→ always 0 or 1 element
Reference
Cheat Sheet
Keep these facts handy while selecting first children.
Topic
Detail
Selector
$("elem:first-child")
Since
jQuery 1.1.4
Matches
0–many (one per parent possible)
Equivalent
:nth-child(1)
vs .first()
Per parent vs one from the set
vs :first-of-type
First of any tag vs first of same tag
CSS?
Yes — standard CSS pseudo-class
Official demo
$("div span:first-child")
Try it
Live Preview
Mark the first child in each group, compare with .first(), or count matches.
Sample: two lists of names. :first-child can hit both lists; .first() hits only one element total.
Ada
Grace
Alan
Linus
Ken
Dennis
Result
Ready — pick an action and click Run.
Code
jQuery Examples
Short, copy-ready snippets. Prefer a typed selector over bare $(":first-child").
Example 1 — Official div span:first-child
Mark the first span in each div — one match per parent.
When div starts with <em> then <span>:
span:first-child → 0, span:first-of-type → 1
How It Works
first-child. Requires the span to be child #1.
first-of-type. Requires the first span among siblings.
Mismatch. An earlier em blocks :first-child.
Choose. Pick the pseudo-class that matches your intent.
Edge Cases & Pitfalls
These mix-ups cause most :first-child surprises.
vs first
Not the same as .first()
:first-child is per parent. .first() is one element from the whole set.
of-type
Wrong pseudo for “first span”
If another tag comes first, use :first-of-type, not :first-child.
scope
Bare $(":first-child") is broad
Prefix with a tag and parent scope to avoid matching the whole document.
index
:nth-child(1) is 1-based
CSS child indexes start at 1 — same as :first-child.
Compatibility
Browser Support
:first-child is a standard CSS pseudo-class. jQuery has supported it since 1.1.4. Works wherever your loaded jQuery build (and the browser CSS engine) runs.
✓ Stable · jQuery 1.1.4+
jQuery :first-child
Universal CSS / jQuery support. Prefer current jQuery 3.x+ for consistent selector engines.
100%CSS + jQuery
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
:first-childUniversal
Bottom line: Safe for everyday UI. Prefer typed, scoped selectors over bare :first-child.
Analysis
Performance Notes
Approach
Cost
Best for
Scoped $("ul.nav li:first-child")
Cheap
Typical UI highlighting
Bare $(":first-child")
Broader
Avoid on large pages
.first() on a small set
Cheap
When you need exactly one
Modern browsers implement :first-child in native CSS. Keep selectors scoped so jQuery does less work.
Remember
Key Takeaways
Role: select elements that are the first child of their parent.
Many matches: one possible first child per parent.
Equals::nth-child(1) — not the same as .first().
Scope: prefer typed selectors like $("li:first-child").
One line::first-child finds the first child per parent — use .first() when you want only one match from a set.
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.
Yes. Official jQuery documentation states that :first-child is equivalent to :nth-child(1).
Yes. :first-child is a standard CSS pseudo-class and works with native querySelectorAll as well. jQuery has supported it since 1.1.4.
The element must be the first element child of its parent. If another element comes before it, or you meant “first of this tag type,” use :first-of-type instead.
Yes — $("li:first-child") or $("div span:first-child") is clearer than bare $(":first-child"). Scoping to a parent avoids matching unintended first children across the page.