CSS Child Combinator (>)

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

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.

CSS Syntax

syntax.css
parent > child { /* styles for direct children only */ }

Example: ul.my-things > li styles only list items that are immediate children of that list.

Common Patterns

PatternDescriptionTry it
div > spanSpans that are direct children of a divTry it
ul > liTop-level list items onlyTry it
.card > h2Heading that is a direct child of .cardTry it
vs spaceCompare > with the descendant spaceTry it
nav > ul > liChain child combinators for a pathTry it
article > pParagraphs directly under an articleTry it

How to Use the Child Combinator

Decide whether nesting should inherit the style. If not, use >.

  1. Identify the parent and the direct child you care about.
  2. Write parent > child { … }.
  3. Check nested copies of the same tag — they should stay unstyled.
  4. Switch to a space combinator only when every depth should match.

Live Preview

Toggle between div > span and div span. Watch which spans turn yellow.

Nested span #2 is a grandchild. Only the descendant mode styles it.

Sample tree
Span #1 (direct child) Span #2 (nested)
Span #3 (outside div)

Mode: div > span

CSS Examples

Yellow marks matches of >. Nested copies stay plain unless you use a descendant selector. Use Try It Yourself for a live editor.

Example 1 — div > span

Style only spans that sit directly inside the div.

CSS
<style>
  div > span {
    background: #fef08a;
  }
</style>

<div>
  <span>Direct child
    <span>Nested</span>
  </span>
</div>
Try It Yourself

How It Works

  1. Parent is div. Only its structure matters for >.
  2. Child must be immediate. The outer span matches.
  3. Nested span skips. It is a grandchild, so no yellow from this rule.
  4. Same idea as MDN. Direct children only.

Example 2 — ul > li

Style top-level list items without styling nested lists the same way.

CSS
<style>
  ul > li {
    font-weight: 700;
    color: #1d4ed8;
  }
</style>

<ul>
  <li>Top
    <ul>
      <li>Nested</li>
    </ul>
  </li>
  <li>Also top</li>
</ul>
Try It Yourself

How It Works

  1. Outer ul > li. Matches items of every ul that are direct children.
  2. Top items bold blue. They sit directly under a list.
  3. Inner li also matches. It is a direct child of the nested ul — still one level under its own parent.
  4. Need outer-only? Scope with a class: .menu > li.

Example 3 — .card > h2

Style the card title without styling headings buried deeper inside.

CSS
<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>
Try It Yourself

How It Works

  1. Parent is .card. Limits the rule to that component.
  2. Direct h2 matches. The title turns purple.
  3. Nested h2 skips. A wrapping div breaks the direct-child link.
  4. 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 lists

Nested 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.

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.

99% Browser support
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.

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

The > combinator matches elements that are direct children of a parent. Nested grandchildren are not matched.
parent > child matches only one level down. parent child (space) matches any depth of descendants.
No. Spaces around > are optional but recommended for readability, for example div > span.
Use it when nested components should not inherit the same styles as top-level children — menus, cards, or list items.
Yes. Patterns like .card > h2 or nav > ul > li are common and valid.
It is Baseline and widely available since about July 2015. It is a browser CSS combinator, not a Node.js API.

Next: descendant combinator

Select nested elements at any depth with a space.

descendant tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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