If you are searching for css selectors eq, the short answer is that CSS has no :eq() pseudo-class. jQuery’s :eq(1) picks the second element of a matched set using a zero-based index, while CSS :nth-child(2) uses a one-based position among element siblings. For a single plain list, add 1 to the jQuery index and you get the CSS number.
This article compares :nth-child() and :nth-of-type(), shows how to combine a class and a position in one compound selector, gives you a small list to test in the HTML Code Editor and CSS Editor, and explains when querySelectorAll() with an index is the better tool. The input is HTML markup plus CSS rules, and the output is a visible highlight you can check by eye.
Table of Contents

CSS selectors eq: why jQuery counts from 0 and CSS counts from 1
jQuery’s position selectors work on a matched set. In $('li.featured:eq(1)'), jQuery first collects every li.featured in document order and then returns the item at index 1, which is the second one. Indexes start at 0, so :eq(0) is the first element. The official jQuery API documentation marks the selector deprecated as of jQuery 3.4 and recommends the separate .eq() method for code that still uses jQuery (checked November 30, 2026).
CSS works differently. A selector is tested against each element on its own, and :nth-child(2) asks one question: is this element the second element child of its parent? The count starts at 1, and the answer can be yes for several parents at once. That gives you two rules to remember.
- Add 1 to a nonnegative jQuery index only when the CSS rule counts the same elements in the same order.
- CSS can match once per parent, while
:eq()returns one element from the whole matched set.
| jQuery index | CSS position | Equivalent only when |
|---|---|---|
:eq(0) | :nth-child(1) | The page has one list and the items are all its element children |
:eq(1) | :nth-child(2) | The same condition holds |
:eq(2) | :nth-of-type(3) | The page has one parent and you want the third item of that tag |
jQuery also accepts negative indexes that count from the end. That is a separate case: the CSS counterpart is :nth-last-child() or :last-child, not a shift by 1.

:nth-child() vs :nth-of-type(): what each selector counts
The two selectors count different things, and the difference only shows when siblings are not all the same tag. li:nth-child(2) matches an li only if it is its parent’s second element child, whatever the first child’s tag is. li:nth-of-type(2) matches the second li among its siblings and ignores siblings of other types. Neither counts text nodes or comments, and neither filters by class before counting. These counting rules are specified in Selectors Level 4, a Working Draft dated January 22, 2026.
A list of identical items hides the difference, so use a container that starts with a heading:
<div class="box"> <h2>Heading</h2> <p>First paragraph</p> <p>Second paragraph</p> </div>
Here p:nth-child(2) selects the first paragraph, because that paragraph is the second child of the div. p:nth-of-type(2) selects the second paragraph, because it is the second p among its siblings. The heading takes position 1 when counting children but is ignored when counting paragraphs.
When you port a jQuery selector, ask which behavior the old code meant. If it was $('.box p:eq(1)'), the intent was the second paragraph, so :nth-of-type(2) is the closer match. If the structure guarantees only one kind of child, both selectors give the same result. I reach for :nth-of-type() when the tag matters and :nth-child() when the slot in the layout matters.

CSS selectors eq with a class: compound AND versus filter-first
jQuery lets you write li.featured:eq(1) and means the second featured item. In CSS, the way to say AND is a compound selector, with the conditions written together without spaces. li.featured:nth-child(2) matches an element that is an li, has the class featured, and is the second element child. All three conditions must be true of the same element. That is the AND CSS selector pattern.
The CSS class selector vs ID selector guide shows the same no-space rule for two classes on one element. A space changes the meaning completely: .featured :nth-child(2) targets a second-child descendant inside a .featured element, which is rarely what you want here.
There is one catch. A compound selector tests the position as a fact about the element and the class as another fact. It does not filter by class and then count. If the second child is not featured, li.featured:nth-child(2) does not move on to the next featured item. To count only featured siblings, use the of clause:
li.featured:nth-child(2) { font-weight: bold; }
.featured :nth-child(2) { color: green; }
:nth-child(2 of li.featured) { outline: 2px solid rebeccapurple; }li:nth-child(2)is the second element child, with any class.li.featured:nth-child(2)is the second element child, but only if it is a featuredli.:nth-child(2 of li.featured)is the second featuredliamong its siblings, wherever it sits.
Compatibility, checked November 30, 2026: the Web Features Explorer lists the of syntax as Widely Available since November 9, 2025, with support starting in Chrome 111 and Edge 111 (March 2023), Firefox 113 (May 2023) and Safari 9 (September 2015). Those minimum versions apply to the of clause, not to basic :nth-child(). The of form still counts per parent, so it is not a perfect copy of jQuery’s whole-set behavior.
Test the demo in the HTML Code Editor and CSS Editor
Use the HTML Code Editor to test exact markup, because it has a sandboxed live preview that renders your page. Paste the document below into it. The rules sit in a style block, so the CSS and the two lists live together.
<style>
.demo > li:nth-child(2) { text-decoration: underline; }
.demo > li.featured:nth-child(2) { font-weight: bold; }
.demo > :nth-child(2 of li.featured) { outline: 2px solid rebeccapurple; }
</style>
<ul class="demo">
<li class="featured">Apple</li>
<li>Banana</li>
<li class="featured">Cherry</li>
</ul>
<ul class="demo">
<li class="featured">Fig</li>
<li class="featured">Grape</li>
</ul>- Look at the preview. Banana and Grape are underlined, only Grape is bold, and Cherry and Grape are outlined.
- Replace
:nth-child(2)in the first rule with:nth-of-type(2). Nothing changes, because every element child in these lists is anli. - Remove the
featuredclass from Grape. The bold and the outline disappear, but the underline stays, because the first rule ignores classes.
The CSS Editor previews your stylesheet on a fixed sample page rather than on your own markup, so pasting the .demo rules there will not highlight anything. Use it to write and edit stylesheet rules with syntax highlighting and property auto-completion, and to see their effect on the sample page. To test how a selector counts elements in your own lists, keep using the HTML Code Editor with the markup above.
When your rules grow, the CSS Beautifier can tidy the indentation and spacing. Beautifying only changes layout. It does not check that a selector matches what you intended.
When querySelectorAll with an index is the better choice
CSS selectors match elements, but they do not pick one result out of a combined list. If you need exactly one element from the matches across all parents, need the element in a script, or calculate the index at runtime, JavaScript is the closer replacement for jQuery’s :eq(). The MDN reference for querySelectorAll() describes a list returned in document order, and ordinary bracket indexing is zero-based, just like jQuery.
const item = document.querySelectorAll('.demo > li.featured')[1];
item?.classList.add('picked');In the demo, the featured items in document order are Apple, Cherry, Fig and Grape, so index 1 returns Cherry only. The CSS rule with of matched Cherry and Grape because it counts per parent. That is the clearest summary of the difference: use CSS when every parent should be styled, and use script when one element across the whole set is the target.
querySelectorAll()returns a staticNodeList. Query again if the DOM changes and you need a fresh result.- An out-of-range index returns
undefined, so guard it, for example with the optional chaining shown above. - Never pass
:eq()toquerySelectorAll(). It is not valid CSS selector syntax and throws aSyntaxError. If you keep jQuery, use the.eq()method instead.
To practice the indexing logic on plain arrays and see synchronous console output, the JavaScript Editor runs code in the browser. It runs in the editor page, so a DOM query only finds elements that exist in that page. Run only code you trust.
Check the result and avoid common mistakes
Most problems with a ported selector come from a handful of causes. Check these first.
- Forgetting the shift from a zero-based to a one-based number.
- Using
:nth-child()when siblings have mixed tags and the tag was what you meant to count. - Adding a space inside what should be a compound selector, which turns it into a descendant selector.
- Expecting a class to filter siblings before counting, when only the
ofclause does that. - Expecting a single match when the rule matches once per parent.
To verify, change one thing at a time and use a visible style such as an outline, so you can count the highlighted elements in the preview. If a rule matches but a style does not apply, the cause may be specificity. A pseudo-class such as :nth-child() adds weight like a class does, and the guide on why a CSS rule inside :where() loses to a plain element selector walks through that kind of check.
Keep the checks separate. A clean preview shows that the rule works in the browser you used. It does not prove support in older browsers, and it does not prove the selector will still match if the markup changes. When the HTML is generated, re-test with the real markup.
Frequently asked questions
Is there an :eq() selector in CSS?
No. CSS has no :eq() pseudo-class. It is a jQuery extension, and jQuery’s documentation marks it deprecated as of version 3.4. In plain CSS you use :nth-child(), :nth-of-type() or the of clause, and in JavaScript you index the result of querySelectorAll().
What is the CSS equivalent of jQuery's :eq()?
For a single list of same-tag siblings, :eq(n) matches :nth-child(n + 1), because CSS counts from 1. It is not an exact replacement, since CSS can match once per parent. Use querySelectorAll() with an index for one element across the whole set.
What is the difference between :nth-child() and :nth-of-type()?
:nth-child(2) matches an element only if it is the second element child of its parent, whatever its tag. :nth-of-type(2) matches the second element of its own tag among siblings. They differ when siblings have mixed tags, such as a heading followed by paragraphs.
How do I write an AND CSS selector with a class and a position?
Write the conditions together without spaces, for example li.featured:nth-child(2). The same element must be an li, have the class featured, and be the second element child. A space would make it a descendant selector, which has a different meaning.
How do I select the second element with a class in CSS?
Use :nth-child(2 of li.featured) to pick the second featured li among its siblings. It filters by class before counting. The compound li.featured:nth-child(2) instead requires the element to be the second child overall and also have the class.
Why does querySelectorAll('li:eq(1)') throw an error?
Because :eq() is not valid CSS selector syntax, so the browser rejects it with a SyntaxError. Query with a standard selector such as li.featured, then take the item at index 1 from the returned list, and guard against an undefined result.
Does :nth-child() count text nodes or comments?
No. It counts only element siblings, so text nodes and comments are ignored. It also does not filter by class before counting, which is why a compound selector like li.featured:nth-child(2) tests position and class as two separate conditions.
Next steps
The css selectors eq answer comes down to three habits: remember that CSS counts from 1, choose between :nth-child() and :nth-of-type() by what you want counted, and use a compound selector or the of clause when a class is part of the condition. Reach for querySelectorAll() with an index when you need a single element from the whole set. As a next step, paste the demo list into the HTML Code Editor, swap the positions and classes, and watch which elements change.
Related tools and resources on HTML Editor Online:
