The :nth-of-type() pseudo-class matches elements by their 1-based position among siblings of the same tag name. Other element types are skipped in that count.
Example: p:nth-of-type(2) is the second p, even if a div sits between paragraphs. Contrast with :nth-child(), which counts every sibling.
Baseline — widely available.
Supported across modern browsers since mid-2015 (CSS3 Selectors). Same odd / even / An+B patterns as the other :nth-* selectors.
Most mix-ups come from expecting class-based counting or child indices.
vs child
Type ≠ child position
p:nth-of-type(2) is not always p:nth-child(2). Prefer of-type when other tags sit between matches.
no nth-class
Not “nth of class”
Counting uses the tag name. For filtered counting by class, use :nth-child(… of .class) where supported.
combine
Class + type still works
p.fancy:nth-of-type(odd) means “odd p that also has .fancy” — the odd count is still among all p tags.
shortcut
(1) equals :first-of-type
Prefer :first-of-type when you only need the first same-tag sibling.
Compatibility
Browser Support
:nth-of-type() is a browser CSS pseudo-class. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
:nth-of-type()
odd, even, and An+B among same-type siblings have been available across browsers for years (CSS3 Selectors). Internet Explorer 9+ supports this selector.
98%Widely available
Google ChromeSupported
Full support
Mozilla FirefoxSupported
Full support
Apple SafariSupported
Full support
Microsoft EdgeSupported
Full support
OperaSupported
Full support
Samsung InternetSupported
Full support
Internet Explorer9+
Supported
:nth-of-type()Baseline · Widely available
Bottom line: Safe for everyday same-type patterns in mixed markup. This is not a JavaScript runtime API.
Remember
Key Takeaways
Role: same-tag siblings, counted from the start (1 = first of that type).
Skips other tags in the count — unlike :nth-child().
Start simple:p:nth-of-type(odd) { … }.
From the end? Use :nth-last-of-type().
One line::nth-of-type() paints by same-tag position — ignore other elements, count from the start.
Frequently Asked Questions
It matches elements by their 1-based position among siblings of the same tag name. Other element types are skipped in the count.
:nth-child() counts every sibling. :nth-of-type() counts only matching tags, so a div between two paragraphs does not change p:nth-of-type(2).
Yes for same-type positions. odd and 2n+1 both match the 1st, 3rd, 5th… of that type. even matches the same set as 2n.
Not with :nth-of-type alone — it keys off the tag name. Combine a class with the pattern (p.fancy:nth-of-type(odd)), or use :nth-child(… of .class) where supported.
Yes. Both select the first sibling of that element type.
No. It is a browser CSS selector. Node.js, Deno, and Bun do not apply it.