CSS Portal

CSS Child Combinator (>) Selector

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The child combinator (>) selector, commonly known as the child combinator, is a CSS selector used to target elements that are direct children of a specified parent element. Unlike the descendant combinator (a space), which selects elements nested at any depth, the > selector ensures that only elements immediately nested inside a parent are matched. This allows for precise styling when the structure of your HTML requires differentiation between levels of nested elements.

For example, consider a structure with multiple levels of nesting:

<ul>
  <li>Item 1</li>
  <li>
    Item 2
    <ul>
      <li>Subitem 2a</li>
    </ul>
  </li>
</ul>

Using the selector ul > li, only the top-level <li> elements (Item 1 and Item 2) would be targeted. The <li> nested inside the second <li> (Subitem 2a) would not be selected because it is not a direct child of the <ul> but rather a grandchild. This illustrates the specificity and control offered by the > selector.

The child combinator (>) selector can be particularly useful when combined with other selectors for more targeted styling. For example, combining it with class selectors allows you to apply rules only to certain child elements without affecting deeper nested structures. It can also be used with pseudo-classes like :nth-child() to style elements based on their position within a parent.

Another common use is in styling nested div elements where you want a parent container to affect only its immediate child div blocks. For instance:

.container > div {
  padding: 10px;
  border: 1px solid #ccc;
}

Here, only the direct <div> children of .container are styled, preventing unintended styles from cascading to deeper nested <div> elements. This makes the > selector a powerful tool for maintaining structured and predictable layouts, especially in complex HTML hierarchies.

The child combinator (>) selector is also essential in modular component design, where you might want to isolate styles within a parent component without affecting nested subcomponents or children that belong to other modules.

Syntax

element > element { css declarations; }

Example

<body>
<div class="parent">
<p>Direct child paragraph 1</p>
<p>Direct child paragraph 2</p>
<div>
<p>Nested paragraph (not direct child)</p>
</div>
</div>
</body>
/* Selects only direct child <p> elements of .parent */
.parent > p {
color: white;
background-color: teal;
padding: 10px;
margin-bottom: 5px;
border-radius: 5px;
}

/* This will not be applied because it's not a direct child */
.parent p p {
color: red;
}

Browser Support

The following information will show you the current browser support for the CSS Child Combinator (>) selector. Hover over a browser icon to see the version that first introduced support for this selector.

This CSS child combinator (>) selector is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 3rd January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!