Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

Child combinator (>)

The > combinator selects elements that are direct children of a specified parent. A > B matches B only when its parent matches A; it does not include descendants nested further down.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

A > B

The selector A > B matches an element satisfying B whose immediate parent satisfies A. Here, A and B are placeholders for selectors, and > is the child combinator, not a comparison operator. The matched element is on the right, not the parent.

Unlike A B, which allows descendants at any depth, A > B requires exactly one parent–child level. Spaces around > are optional: .panel>p and .panel > p mean the same thing.

In the example, .panel > p matches only #direct. The parent of #nested is section, so that paragraph does not match. The p rule explicitly sets the baseline color. Remember that failing to match a selector does not prevent an element from inheriting properties from its parent.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Child combinator</title>
  <style>
    p { color: black; }
    .panel > p { color: blue; }
  </style>
</head>
<body>
  <div class="panel">
    <p id="direct">Direct child</p>
    <section>
      <p id="nested">Nested descendant</p>
    </section>
  </div>
</body>
</html>

Result

#direct: rgb(0, 0, 255)
#nested: rgb(0, 0, 0)

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources