The :first-of-type pseudo-class matches an element that is the first of its tag name among sibling elements.
Example: p:first-of-type styles the first p under a parent, even if an h2 comes before it. Same match as :nth-of-type(1). For “must be first child of any type,” use :first-child.
Baseline · Widely available.
Not deprecated. A long-standing structural pseudo-class from Selectors Level 3 / 4.
First dd only.dd:first-of-type matches the first dd in that sibling list (Tomatoes).
Later dds. Cucumbers, Apples, and Mangos are not the first of type.
Note. There is only one “first dd” under the whole dl—not one per dt.
Example 3 — Nested First-of-Type
Each parent can have its own first-of-type match.
CSS
<style>
article :first-of-type {
background-color: pink;
}
</style>
<article>
<div>This div is first!</div>
<div>This <span>nested span is first</span>!</div>
<p>This p qualifies!</p>
<div>This is the final div.</div>
</article>
Descendant selector.article :first-of-type looks for first-of-type under article.
Outer siblings. The first div and the only p match among article children.
Nested. The span is the first (and only) of its type inside its parent div.
Implied *. Writing :first-of-type without a tag means any type.
Edge Cases & Pitfalls
Confusion with :first-child causes most mistakes.
vs child
Not the same as :first-child
Need the absolute first child of any tag? Use :first-child.
dl
One first dd per parent
dd:first-of-type matches the first dd among all siblings in the dl, not the first under each dt.
alias
Same as :nth-of-type(1)
:first-of-type and :nth-of-type(1) select the same elements.
scope
Per parent, not per page
Each parent has its own sibling list. Nested containers can each match.
only
Single of that type still matches
One p among siblings is still first of type. For “exactly one of that type,” use :only-of-type.
Compatibility
Browser Support
:first-of-type is a browser CSS selector. Node.js, Deno, and Bun do not evaluate it.
✓ Baseline · Widely available
:first-of-type
Supported in all modern browsers (Chrome 1+, Firefox 3.5+, Safari 3.1+, Edge 12+, IE 9+).
98%Global support
Google Chrome1+
Full support
Mozilla Firefox3.5+
Full support
Apple Safari3.1+
Full support
Microsoft Edge12+
Full support
Opera9.5+
Full support
Samsung Internet1+
Full support
Internet Explorer9+
Full support
:first-of-typeWidely supported
Bottom line: Safe for production structural styling. It is not a JavaScript runtime API.
Remember
Key Takeaways
Role: match the first sibling of a given tag type.
Form:E:first-of-type = first E among siblings.
vs :first-child: of-type allows other tags before the match.
Alias: same match as :nth-of-type(1).
One line::first-of-type styles the first element of that tag among siblings—even if another tag sits before it.
Frequently Asked Questions
It matches an element that is the first sibling of its tag type inside its parent. Other element types before it do not block the match.
:first-child requires the element to be the first child of any type. :first-of-type matches the first p, first li, or first div of that tag among siblings, even if another tag comes first.
Yes. If the parent contains an h2 then paragraphs, p:first-of-type matches the first p even though the h2 is the overall first child.
Yes. :first-of-type matches the same elements as :nth-of-type(1).
Yes. Each parent has its own sibling group. article :first-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.