CSS Child Selector (>)

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Combinators

What You’ll Learn

The element > element selector — also called the child combinator — targets only direct children of a parent. It gives you precise control over nested HTML without accidental styling of deeper elements.

01

> combinator

Direct children.

02

Syntax

parent > child

03

Containers

First-level only.

04

Navigation

ul > li

05

vs space

Child vs descendant.

06

Clean CSS

Avoid bleed-through.

Introduction

The element > element selector in CSS is a child combinator that selects elements which are direct children of a specified parent element.

This selector lets you target one level deep in the DOM tree. Styles apply to immediate children only and do not cascade to grandchildren or deeper nested elements.

Definition and Usage

Write the parent selector, a greater-than sign (>), then the child selector. The rule applies only when the child is an immediate descendant of the parent. If another element sits between them, the selector does not match.

💡
Beginner Tip

Think of > as “one level down only.” If you need all nested elements at any depth, use the descendant combinator (a space) instead: .parent p.

📝 Syntax

The signature of the child combinator is:

syntax.css
parent > child {
  /* CSS properties */
}

Basic Example

child-selector.css
.container > h1 {
  color: #2563eb;
  font-size: 1.5rem;
}

.container > .content {
  background: #eff6ff;
  padding: 0.75rem 1rem;
  border-radius: 8px;
}

Syntax Rules

  • The child must be a direct descendant of the parent.
  • Grandchildren and deeper nested elements are not matched.
  • Spaces around > are conventional: .parent > p.
  • Works with element types, classes, IDs, and attribute selectors.
  • Can be chained: nav > ul > li for each level.

Related Selectors

  • element element — descendant combinator (any nested level)
  • element + element — adjacent sibling combinator
  • element ~ element — general sibling combinator

⚡ Quick Reference

QuestionAnswer
Combinator symbol> (greater-than)
Also calledChild combinator
MatchesOnly direct children (one level deep)
Common patterns.container > h1, ul > li, .content > p
Alternative for all nestedelement element (descendant)
Browser supportAll modern browsers
.container > h1 ul > li .content > p nav > ul > li

When to Use element > element

The child combinator is ideal when you need one-level precision:

  • Layout sections — Style only top-level blocks inside a container without affecting nested widgets.
  • Navigation menus — Target ul > li for top-level items while leaving dropdown sub-menus alone.
  • Article content — Style direct paragraphs in .content > p but not quotes inside nested divs.
  • Tables — Use table > thead or table > tbody for structural styling.
  • Component boundaries — Prevent styles from bleeding into child components rendered inside a parent.

👀 Live Preview

Only direct children of .child-demo-wrap are styled — the nested paragraph inside .child-demo-panel is not affected by > h3 or > .child-demo-panel rules on outer elements:

Main Title (direct child)

Paragraph inside the panel (not a direct child of .child-demo-wrap).

Examples Gallery

Practice the > combinator with containers, navigation, direct paragraphs, and child vs descendant comparison.

📜 Core Patterns

Style direct children inside a parent container.

Example 1 — Container direct children

Style the <h1> and .content div only when they are immediate children of .container.

container-child.css
.container > h1 {
  color: #2563eb;
  font-size: 1.5rem;
}

.container > .content {
  background: #eff6ff;
  padding: 0.75rem 1rem;
  border-radius: 8px;
}
Try It Yourself

How It Works

The <h1> and .content sit directly inside .container, so they match. A nested <p> inside .inner would not match .container > p.

Example 2 — Top-level menu items

Use ul.menu > li to style only direct list items in a horizontal navigation bar.

menu-child.css
.menu {
  display: flex;
  gap: 0.5rem;
  list-style: none;
  padding: 0;
}

.menu > li {
  padding: 0.45rem 0.85rem;
  background: #f1f5f9;
  border-radius: 6px;
  font-weight: 600;
}
Try It Yourself

How It Works

Each <li> is a direct child of <ul class="menu">. If you add nested sub-menus with inner <ul> lists, .menu > li still targets only the top-level items.

📄 Precision Patterns

Limit styles to one nesting level and compare with descendant selectors.

Example 3 — Direct paragraphs only

Style paragraphs that are immediate children of .content, leaving nested paragraphs unchanged.

content-child-p.css
.content > p {
  color: #16a34a;
  font-weight: 600;
}
Try It Yourself

How It Works

The paragraph inside .inner is a grandchild of .content, so .content > p does not match it. Only direct <p> children are styled green.

Example 4 — Child (>) vs descendant (space)

See how .parent > p differs from .parent p when paragraphs are nested inside another element.

child-vs-descendant.css
/* Direct children only */
.child-only > p {
  color: #2563eb;
  font-weight: 600;
}

/* All nested paragraphs */
.all-nested p {
  color: #dc2626;
  font-weight: 600;
}
Try It Yourself

How It Works

The descendant selector matches every <p> inside the parent at any depth. The child combinator stops at the first level, giving you tighter control over complex markup.

⚠️ Common Pitfalls

  • Expecting nested matches> only selects direct children. Grandchildren need a separate rule or the descendant combinator.
  • Wrong HTML structure — If an extra wrapper div sits between parent and child, the selector will not match.
  • Confusing > with +> is parent-to-child. + is sibling-to-sibling at the same level.
  • Over-specificity — Long chains like div > div > div > p are fragile when markup changes; prefer classes when structure varies.

♿ Accessibility

  • Semantic HTML — Use proper elements (nav, ul, li, main) so child selectors align with meaningful structure.
  • Navigation — When styling ul > li, ensure keyboard users can reach all menu items and sub-menus remain accessible.
  • Don’t hide content accidentally — Be careful with display: none on child selectors that might hide important nested content.
  • Focus styles — Child selectors for layout should not remove :focus outlines from interactive elements inside.

🧠 How element > element Works

1

Browser finds the parent

Every element matching the parent selector becomes a starting point.

Parent
2

> checks one level down

The browser looks only at immediate children of each matched parent.

Child
3

Child selector filters matches

Only direct children that match the second selector receive the styles.

Match
=

Precise one-level styling

Nested descendants stay untouched unless you target them separately.

Browser Compatibility

The child combinator (>) is supported in all modern browsers and has been part of CSS for decades.

Universal · All browsers

Child combinator everywhere

element > element works reliably in Chrome, Firefox, Safari, Edge, and Opera.

99% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
> child combinator 99% supported

Bottom line: The child combinator is safe for layout and navigation patterns in any modern project.

Conclusion

The element > element child combinator is an essential tool for precise CSS targeting. It lets you style direct children without affecting deeper nested elements, leading to cleaner and more maintainable stylesheets.

Use it for containers, navigation, and component boundaries. When you need all nested elements, switch to the descendant combinator. Combine child selectors with classes for flexible, readable CSS.

💡 Best Practices

✅ Do

  • Use .parent > .child when you need one-level precision
  • Combine with semantic HTML (nav > ul > li)
  • Compare with descendant selectors to avoid unintended matches
  • Add classes to children when markup depth varies
  • Keep selector chains readable with spaces around >

❌ Don’t

  • Expect > to match grandchildren
  • Confuse > with the adjacent sibling +
  • Build overly long fragile chains tied to exact DOM depth
  • Use child selectors when a simple class on the target is clearer
  • Forget that wrapper divs break direct parent-child relationships

Key Takeaways

Knowledge Unlocked

Five things to remember about >

Use these points when targeting direct children in your CSS.

5
Core concepts
📁 02

Containers

Top-level blocks.

Pattern
03

ul > li

Menu items.

Nav
📄 04

vs space

Child vs descendant.

Compare
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The child combinator (parent > child) selects elements that are direct children of the specified parent. Deeper nested descendants are not matched.
The > child combinator matches only direct children. The descendant combinator (a space) matches any nested level inside the parent.
Yes. Selectors like .container > h1, nav > .menu-item, and ul > li work the same way — the second part must be an immediate child of the first.
Use it when you need precise control — for example styling only top-level list items, direct table rows, or first-level sections without affecting nested components.
Yes. The > combinator has been supported in all modern browsers for many years and is safe to use in production.

Practice in the Live Editor

Open the HTML editor and experiment with .container > h1, ul > li, and child vs descendant selectors.

HTML Editor →

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.

5 people found this page helpful