Skip to content
Justice Tech School

Combinators

A space (descendant) matches any nested element: nav a. The > symbol (child) matches only direct children. + (adjacent sibling) matches the element immediately after another, and ~ (general sibling) matches all following siblings.

Combinators let you style based on where an element sits in the markup, without adding extra classes.

Example
<style>
  .box p { color: crimson; }
  .box > span { color: seagreen; }
  h3 + p { font-weight: bold; }
</style>
<div class="box">
  <p>Descendant paragraph</p>
  <span>Direct child span</span>
</div>
<h3>Heading</h3>
<p>Right after the heading (bold)</p>
<p>Not bold</p>

Exercise

Select only direct children of .menu that are li.

.menu  li {
  color: blue;
}

Quiz Test

Which combinator selects an element immediately following another?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.