CSS: child selector (>)

By Xah Lee. Date: . Last updated: .

Match a Parent Tag (aka Child Combinator)

s1 > s2

Match any s2 that is a direct child of s1.

Each expression can be compound selector.

Can also be chained like this:

a > b > c

/* any span that's direct child of div */
div > span {
 color: red;
}
<div>
 <span>match</span>
</div>

<div>
 <p>
  <span>no</span>
 </p>
</div>

Example. Less space of h2 inside section

/* the first h2 after section */
section > h2 {
 margin-top: 1ex;
}

CSS, Selectors

simple selectors
selector list
relationship selectors (combinators)
special selector
misc