The :last-of-type pseudo-class matches an element that is the last of its tag name among sibling elements.
Example: p:last-of-type styles the last p under a parent, even if a div footer comes after it. Same match as :nth-last-of-type(1). For “must be last child of any type,” use :last-child.
Baseline · Widely available.
Not deprecated. A long-standing structural pseudo-class from Selectors Level 3 / 4.
Last dd only.dd:last-of-type matches the last dd in that sibling list (Oranges).
Earlier dds. Tomatoes, Cucumbers, and Apples are not the last of type.
Note. There is only one “last dd” under the whole dl—not one per dt.
Example 3 — Nested Last-of-Type
Each parent can have its own last-of-type match.
CSS
<style>
article :last-of-type {
background-color: pink;
}
</style>
<article>
<div>This div is first.</div>
<div>This <span>nested span is last</span>!</div>
<div>This <em>nested em is first</em>, but this <em>nested em is last</em>!</div>
<p>This p qualifies!</p>
<div>This is the final div!</div>
</article>
Each parent has its own sibling list. Nested containers can each match.
only
Single of a type also matches
The only p under a parent is still the last of type. For “exactly one of that type,” use :only-of-type.
Compatibility
Browser Support
:last-of-type is a browser CSS selector. Node.js, Deno, and Bun do not evaluate it.
✓ Baseline · Widely available
:last-of-type
Supported in all modern browsers (Chrome 1+, Firefox 3.5+, Safari 3.2+, Edge 12+, Opera 9.5+, IE 9+).
97%Global support
Google Chrome1+
Full support
Mozilla Firefox3.5+
Full support
Apple Safari3.2+
Full support
Microsoft Edge12+
Full support*
Opera9.5+
Full support
Samsung Internet1+
Full support
Internet Explorer9+
Full support*
:last-of-typeWidely supported
Bottom line: *IE and very old Edge treated unknown/custom tags as one type. Safe for standard HTML on modern sites. It is not a JavaScript runtime API.
Remember
Key Takeaways
Role: match the last sibling of a given tag under a parent.
Form:E:last-of-type = last element of tag E.
vs :last-child: of-type still matches when another tag follows.
Alias: same match as :nth-last-of-type(1).
One line::last-of-type styles the last sibling of a tag, even if other element types come after it.
Frequently Asked Questions
It matches an element that is the last sibling of its tag type inside its parent. Other element types after it do not block the match.
:last-child requires the element to be the last child of any type. :last-of-type matches the last p, last li, or last div of that tag among siblings, even if another tag comes after it.
Yes. If the parent contains paragraphs then a div footer, p:last-of-type matches the last p even though the div is the overall last child.
Yes. :last-of-type matches the same elements as :nth-last-of-type(1).
Yes. Each parent has its own sibling group. article :last-of-type can match inside every nested parent, not only once on the page.
No. It is a CSS selector evaluated by the browser layout engine, not a Node.js or server runtime feature.