The :first-of-type pseudo-class matches the first element of a given tag type among its siblings. It is ideal when a heading or other element appears before your target.
01
By tag type
First p, li…
02
Siblings
Same parent.
03
vs :first-child
Ignores other tags.
04
Lists
First li each ul.
05
Articles
First paragraph.
06
Nested
Per container.
Fundamentals
Introduction
The :first-of-type selector in CSS is a structural pseudo-class used to target the first element of a specific type within its parent container.
Unlike :first-child, it ignores other tag types that appear earlier among siblings. This makes it perfect for styling the first paragraph after a heading, or the first list item in each list.
Definition and Usage
Write the element selector before the pseudo-class: p:first-of-type or li:first-of-type. The rule matches when that element is the first of its tag name among siblings inside the same parent.
💡
Beginner Tip
If a container has <h2> followed by three <p> tags, p:first-of-type matches the first paragraph — even though the heading is the first child overall.
Foundation
📝 Syntax
The syntax for the :first-of-type pseudo-class is:
syntax.css
element:first-of-type{/* CSS properties */}
Here, element is the HTML tag you want to target (such as p, li, or div). Only the first sibling of that type inside each parent matches.
Matching is based on element type, not overall child position.
Each parent creates a separate sibling group for matching.
Combine with combinators: ul > li:first-of-type for direct children.
Different from :first-child, which requires being the first child of any type.
Works with any element type that can appear multiple times as siblings.
:first-of-type vs :first-child
Markup
p:first-of-type
p:first-child
<h2><p><p>
Matches first p
Does not match (h2 is first child)
<p><p><p>
Matches first p
Matches first p
Related Selectors
:last-of-type — matches the last element of a type among siblings
:nth-of-type() — matches by index among elements of the same type
:first-child — matches only when the element is the first child overall
:only-of-type — matches when it is the sole element of its type among siblings
Cheat Sheet
⚡ Quick Reference
Question
Answer
Selector type
Structural pseudo-class
When it applies
Element is the first of its tag type among siblings
Other tags before it
Allowed — only same-type order matters
Common use
First paragraph after a heading, first li in each list
Typical pattern
article p:first-of-type { font-weight: 700; }
Browser support
All modern browsers
Context
When to Use :first-of-type
:first-of-type is the right choice when tag type matters more than overall position:
Article body — Style the first paragraph even when a heading comes first.
Multiple lists — Highlight the first item in every <ul> on the page.
Mixed content blocks — Target the first <div> in a section with varied markup.
Table rows — Style the first <tr> in each <tbody>.
When :first-child fails — Use when another element type precedes your target.
Preview
👀 Live Preview
An h2 comes first, but p:first-of-type still bolds and blues the first paragraph:
Article Section
This is the first paragraph in the section.
This is the second paragraph in the section.
This is the third paragraph in the section.
Hands-On
Examples Gallery
Practice :first-of-type with paragraphs, list items, mixed markup, and comparison with :first-child.
📜 Core Patterns
Style the first element of a specific tag type inside a parent.
Example 1 — First paragraph after a heading
Bold and color the first <p> in a section, even when an <h2> appears first.
first-of-type-paragraph.html
<style>p:first-of-type{font-weight:700;color:#2563eb;}</style><divclass="container"><h2>Article Section</h2><p>This is the first paragraph in the section.</p><p>This is the second paragraph in the section.</p><p>This is the third paragraph in the section.</p></div>
The paragraph before the divs does not block div:first-of-type. Only siblings of the same tag type are counted.
Example 4 — :first-of-type vs :first-child side by side
See why p:first-child fails when a <div> is first, but p:first-of-type succeeds.
first-of-type-vs-child.css
/* Does NOT match — div is first child */p:first-child{color:#ef4444;}/* DOES match — first p among siblings */p:first-of-type{color:#2563eb;font-weight:700;}
First paragraph styled blue by :first-of-type (not :first-child).
How It Works
When another element type precedes your target, reach for :first-of-type instead of :first-child.
Watch Out
⚠️ Common Pitfalls
Confusing with :first-child — They behave differently when mixed element types are present.
Wrong parent scope — Matching happens among direct siblings only; nested elements have their own groups.
Expecting first of any type — p:first-of-type never matches a div; you must specify the tag.
Single element of type — If only one p exists, it is both first and last of type; that is expected.
Dynamic DOM changes — Inserting a new sibling of the same type before your target moves which element matches.
A11y
♿ Accessibility
Do not rely on position styling alone — Visual emphasis on the first item should not be the only cue for importance.
Semantic HTML first — Use proper headings and lists; pseudo-classes enhance presentation.
Color contrast — Ensure styled first paragraphs and list items meet WCAG contrast requirements.
Screen readers — Position-based styling does not change reading order or announcements.
🧠 How :first-of-type Works
1
Browser finds candidate elements
CSS gathers elements matching the tag in your selector, such as all p elements.
Match
2
Checks type order among siblings
Within each parent, the browser asks: is this the first sibling of this tag type?
Position
3
Styles apply to matches
Only the first of each type in every sibling group receives the rule.
Render
=
📄
Type-aware styling
The first paragraph, list item, or div of its kind stands out in each container.
Compatibility
🖥 Browser Compatibility
The :first-of-type pseudo-class is supported in all modern browsers and has been available since CSS3.
✓ Baseline · Universal support
Structural selectors everywhere
:first-of-type works reliably in Chrome, Firefox, Safari, Edge, and Opera.
99%Universal support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
:first-of-type pseudo-class99% supported
Bottom line::first-of-type is safe for lists, articles, and mixed markup in all modern projects.
Wrap Up
🎉 Conclusion
The :first-of-type pseudo-class is a versatile structural selector for targeting the first element of a specific tag among siblings. It solves cases where :first-child fails because another element type comes first.
Use it for first paragraphs after headings, first items in each list, and any layout where tag type matters more than overall position. Pair it with :last-of-type and :nth-of-type() for complete positional control.
Choose :first-of-type when mixed tags precede your target
Combine with child combinator for direct children
Compare with :first-child in DevTools when debugging
❌ Don’t
Confuse :first-of-type with :first-child
Expect it to match the first element of any type
Forget that each parent has its own sibling group
Rely on position styling alone for meaning
Assume nested elements share one global count
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about :first-of-type
Use these points when styling by element type.
5
Core concepts
1st01
By tag type
First p, li.
Purpose
≠02
vs first-child
Different rules.
Compare
📄03
After headings
First paragraph.
Use case
📝04
Per parent
Own group.
Scope
🌐05
99% support
All browsers.
Compat
❓ Frequently Asked Questions
The :first-of-type pseudo-class matches an element when it is the first sibling of its tag type inside its parent. Other element types appearing before it do not prevent a match.
:first-child requires the element to be the very first child of any type. :first-of-type matches the first p, first li, or first div of that tag among siblings, even if a different tag comes first.
Yes. If the parent contains h2 then p elements, p:first-of-type matches the first p even though the h2 is the first child overall.
Yes. Each parent creates its own sibling group. ul li:first-of-type matches the first li inside each ul, not just the first li on the entire page.
Yes. All modern browsers support :first-of-type. It has been available since CSS3 and works reliably for lists, articles, and layout patterns.