The :nth-last-of-type() pseudo-class matches elements by their position among siblings of the same tag name, counting from the end. Other element types are skipped in that count.
Example: span:nth-last-of-type(2) styles the second-to-last span, even if an em or div sits between spans. Contrast with :nth-last-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.
Differs when headings or other tags share the parent.
Edge Cases & Pitfalls
Most mix-ups come from confusing type counts with child counts.
vs child
Type ≠ child position
span:nth-last-of-type(2) is not always the same node as span:nth-last-child(2). Use of-type when other tags sit between matches.
tag only
Classes do not define the count
Counting uses the element type. .note:nth-last-of-type(1) still means “last of that tag that also has .note,” not “last .note among classes.”
direction
Same formula, from the end
-n+3 is “first three of type” with :nth-of-type() and “last three of type” here.
shortcut
(1) equals :last-of-type
Prefer :last-of-type when you only need the final same-tag sibling.
Compatibility
Browser Support
:nth-last-of-type() is a browser CSS pseudo-class. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
:nth-last-of-type()
odd, even, and An+B among same-type siblings from the end 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-last-of-type()Baseline · Widely available
Bottom line: Safe for everyday same-type reverse patterns in mixed markup. This is not a JavaScript runtime API.
Remember
Key Takeaways
Role: same-tag siblings, counted from the end (1 = last of that type).
Skips other tags in the count — unlike :nth-last-child().
Start simple:span:nth-last-of-type(2) { … }.
Shortcut:(1) = :last-of-type.
One line::nth-last-of-type() is reverse same-tag counting — ignore other elements, count from the end.
Frequently Asked Questions
It matches elements by their 1-based position among siblings of the same tag name, counting from the end. Other tag types are skipped in the count.
Yes. Both select the last sibling of that element type. Prefer :last-of-type when you only need that one case.
:nth-last-child() counts every sibling from the end. :nth-last-of-type() counts only matching tags from the end, ignoring other element types in between.
Use p:nth-last-of-type(-n+3). It matches the last, second-to-last, and third-to-last p among the parent's p children.
No. It keys off the element type (tag name), not classes or IDs. Combine with a class if you need both: p.note:nth-last-of-type(1).
No. It is a browser CSS selector. Node.js, Deno, and Bun do not apply it.