The :first selector matches exactly one element — the first in the matched set, in document order. Equivalent to :eq(0). jQuery extension since 1.0; deprecated in 3.4 — prefer the .first() method.
01
Syntax
tr:first
02
One match
Single element
03
Official
tr italic
04
= :eq(0)
Equivalent
05
vs :first-child
Many per parent
06
.first()
Modern replacement
Fundamentals
Introduction
When you have many matching elements — table rows, list items, or cards — you often need only the first one in document order. The jQuery :first pseudo-class narrows a matched set to that single leading element.
jQuery has supported :first since version 1.0. Official documentation states it selects the first matched DOM element and is equivalent to :eq(0). As of jQuery 3.4, the selector is deprecated — use .first() on a CSS-selected collection instead.
Concept
Understanding the :first Selector
Think of :first as “keep only index 0 from this matched set”:
$("tr:first") → one row — the first tr in document order.
$("li:first") → one list item — the very first li on the page (in scope).
Equivalent to :eq(0) and :lt(1) per official jQuery docs.
Not the same as :first-child — that can match one element per parent.
💡
Beginner Tip
Need the first item in every list? Use $("ul li:first-child"), not $("li:first"). The former returns many; the latter returns one.
Foundation
📝 Syntax
Official jQuery API form (since 1.0; deprecated 3.4):
No arguments — keeps the first element from the matched set that precedes :first.
Return value
A jQuery object containing zero or one element.
Empty collection when the preceding selector matched nothing.
Official jQuery API example
jQuery
$( "tr:first" ).css( "font-style", "italic" );
Cheat Sheet
⚡ Quick Reference
Goal
:first
.first()
First table row
tr:first
$("tr").first()
Same as :eq(0)
li:first
$("li").eq(0)
First li in document
One element
One element
First li in each list
Not :first
Use li:first-child
Native CSS
Not supported
jQuery method only
Compare
📋 :first vs :eq(0), .first(), and :first-child
Set index vs sibling position — one global match vs one per parent.
:first
li:first
One element total
:eq(0)
li:eq(0)
Equivalent
.first()
$("li").first()
Modern replacement
:first-child
li:first-child
One per parent
Hands-On
Examples Gallery
Example 1 follows the official jQuery tr:first demo. Examples 2–5 cover equivalence with :eq(0), migration to .first(), contrast with :first-child, and scoped list selection.
📚 Official jQuery Demo
Italicize the first table row in the matched set.
Example 1 — Official Demo: tr:first
Official jQuery demo — Row 1 italic; Row 2 and Row 3 unchanged.
Home → bold blue (first li in ul.nav)
Dashboard in second nav list → unchanged
Other items → default styling
How It Works
Prefixing with ul.nav builds a smaller matched set — the first match is the lead nav link, not the first li on the entire page.
Applications
🚀 Common Use Cases
Table headers — style tr:first or thead tr:first for emphasis.
Lead list item — highlight the first entry in a flat collection with li:first.
First card in a grid — .card:first for featured layout (legacy code).
Legacy maintenance — understand :first when reading older jQuery projects.
Migration — replace with $("selector").first() in modern codebases.
Performance — select with CSS first, then .filter(":first") or .first().
🧠 How jQuery Evaluates :first
1
Build matched set
Evaluate the selector before :first — e.g. all tr elements.
Query
2
Order by document
Elements stay in document order — official docs note this explicitly.
Index
3
Keep index 0
:first discards all but the first element — same as :eq(0).
Filter
4
✓
Return collection
Chain .css() or other jQuery methods on zero or one element.
Important
📝 Notes
Available since jQuery 1.0 — deprecated in 3.4; prefer .first().
Equivalent to :eq(0) and :lt(1) — official jQuery documentation.
Matches only one element — unlike :first-child which can match many.
jQuery extension — not valid in native querySelectorAll.
For performance, use a pure CSS selector first, then .filter(":first") or .first().
Do not confuse with CSS :first-child or :first-of-type — different rules entirely.
Compatibility
Browser Support
The :first pseudo-class is a jQuery extension — not standard CSS — and works in jQuery 1.0+. It is deprecated in 3.4+; use .first() instead. The method works in all browsers that support jQuery.
✓ jQuery 1.0+ · deprecated 3.4
jQuery :first Selector
Use $("tr").first() in new code — not tr:first in selector strings.
100%jQuery only
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
:firstDeprecated
Bottom line: Migrate to .first() — select with CSS, then filter in jQuery.
Wrap Up
Conclusion
The :first selector matches exactly one element — the first in the matched set. The official tr:first demo italicizes Row 1 only.
Remember equivalence with :eq(0), distinguish it from :first-child, and migrate to .first() in jQuery 3.4+ projects.
Choose :first-child when every parent needs a first item
Remember :first equals :eq(0) in legacy code
Select with CSS first for better performance
❌ Don’t
Use :first in new selector strings (deprecated 3.4)
Confuse :first with :first-child or :first-of-type
Assume :first returns one item per parent
Use bare $(":first") without a preceding selector
Expect :first to work in querySelectorAll
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :first
First element in the matched set only.
5
Core concepts
101
:first
One match
API
002
= :eq(0)
Equivalent
Rule
≠03
Not :first-child
Per parent differs
Compare
demo04
Official
tr italic
Demo
.first()05
Deprecated
Use method
Tip
❓ Frequently Asked Questions
:first selects exactly one element — the first in the matched set that precedes it, in document order. $("tr:first") matches only the first table row among all tr elements in scope. Available since jQuery 1.0.
Yes. Official jQuery documentation states that :first is equivalent to :eq(0). It could also be written as :lt(1). All three return a single element at index 0 of the matched set.
Yes — deprecated in jQuery 3.4. Official docs recommend removing :first from selectors and using the .first() method after a pure CSS selector instead: $("tr").first() rather than $("tr:first").
:first returns one element total from the matched set. :first-child can return many — one per parent. Official docs highlight this distinction explicitly.
No. :first is a jQuery extension and not part of the CSS specification. It does not work in native querySelectorAll. Use .first() on a CSS-selected collection for modern code.
:first always follows a selector that builds the matched set — e.g. $("li:first") not $(":first"). Index selectors (:first, :eq, :lt, :gt, :even, :odd) narrow the set produced by what comes before them.
Did you know?
:first could also be written as :lt(1) — both keep elements with index less than 1, which is only index 0. Official jQuery docs list all three forms as equivalent.