Home CSS Selectors child (>) CSS Child Combinator (>) Definition
Definition and Usage The child combinator (>) sits between two selectors. It matches elements from the second selector that are direct children of elements from the first.
It is stricter than the descendant combinator (a space), which matches any nesting depth. Use > when nested items must not get the same styles as top-level children.
Baseline · Widely available. Not deprecated. Cross-browser since about July 2015.
Whitespace tip. Spaces around > are optional. Prefer div > span for readability.
Syntax
CSS Syntax parent > child { /* styles for direct children only */ }
Example: ul.my-things > li styles only list items that are immediate children of that list.
Patterns
Common Patterns Pattern Description Try it div > spanSpans that are direct children of a div Try itul > liTop-level list items only Try it.card > h2Heading that is a direct child of .card Try itvs space Compare > with the descendant space Try itnav > ul > liChain child combinators for a path Try itarticle > pParagraphs directly under an article Try it
Approach
How to Use the Child Combinator Decide whether nesting should inherit the style. If not, use >.
Identify the parent and the direct child you care about. Write parent > child { … }. Check nested copies of the same tag — they should stay unstyled. Switch to a space combinator only when every depth should match. Try it
Live Preview Toggle between div > span and div span. Watch which spans turn yellow.
Code
CSS Examples Yellow marks matches of >. Nested copies stay plain unless you use a descendant selector. Use Try It Yourself for a live editor.
1. div > span 2. ul > li 3. .card > h2 Example 1 — div > span Style only spans that sit directly inside the div.
<style>
div > span {
background: #fef08a;
}
</style>
<div>
<span>Direct child
<span>Nested</span>
</span>
</div> How It Works Parent is div. Only its structure matters for >.Child must be immediate. The outer span matches.Nested span skips. It is a grandchild, so no yellow from this rule.Same idea as MDN. Direct children only.Example 2 — ul > li Style top-level list items without styling nested lists the same way.
<style>
ul > li {
font-weight: 700;
color: #1d4ed8;
}
</style>
<ul>
<li>Top
<ul>
<li>Nested</li>
</ul>
</li>
<li>Also top</li>
</ul> How It Works Outer ul > li. Matches items of every ul that are direct children.Top items bold blue. They sit directly under a list.Inner li also matches. It is a direct child of the nested ul — still one level under its own parent.Need outer-only? Scope with a class: .menu > li.Example 3 — .card > h2 Style the card title without styling headings buried deeper inside.
<style>
.card > h2 {
color: #7c3aed;
margin: 0 0 0.5rem;
}
</style>
<div class="card">
<h2>Card title</h2>
<div>
<h2>Nested heading</h2>
</div>
</div> How It Works Parent is .card. Limits the rule to that component.Direct h2 matches. The title turns purple.Nested h2 skips. A wrapping div breaks the direct-child link.Safer components. Inner widgets keep their own heading styles. Edge Cases & Pitfalls Most surprises come from assuming > skips nested lists entirely, or from confusing it with siblings.
depth Only one level under that parent section > p ignores a p wrapped in another element inside the section.
lists ul > li still hits nested listsNested li elements are direct children of their own ul. Scope with a class when you need outer items only.
vs-space Space is not the same div span matches every nested span. Use descendant when that is intentional.
siblings Not + or ~ Adjacent (+ ) and general (~ ) siblings select next to an element, not under it.
whitespace Text nodes do not break > Spaces and newlines between tags are fine. The combinator still sees the element children.
Compatibility
Browser Support The child combinator (>) is a browser CSS selector feature . Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
Child combinator (>) Supported in all modern browsers and IE 7+. Widely available since July 2015.
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 4+
Full support
Samsung Internet 1+
Full support
Internet Explorer 7+
Full support > Widely supported
Bottom line: Safe for precise layout targeting everywhere. Prefer > when nesting should not inherit. It is not a runtime API.
Remember
Key Takeaways Role: match only direct children with parent > child.
vs space: descendant matches any depth; > is one level.
Scope lists: use a class when nested ul > li should differ.
Readable: keep spaces around >.
One line: use > when only direct children should get the style.
Frequently Asked Questions What does the CSS child combinator do? The > combinator matches elements that are direct children of a parent. Nested grandchildren are not matched.
What is the difference between > and a space? parent > child matches only one level down. parent child (space) matches any depth of descendants.
Is whitespace around > required? No. Spaces around > are optional but recommended for readability, for example div > span.
When should I use >? Use it when nested components should not inherit the same styles as top-level children — menus, cards, or list items.
Can I combine > with classes? Yes. Patterns like .card > h2 or nav > ul > li are common and valid.
Which browsers support the child combinator? It is Baseline and widely available since about July 2015. It is a browser CSS combinator, not a Node.js API.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion