CSS · CSS Tutorial · Lesson 28
CSS Combinators
Descendant, child, adjacent and general sibling selectors.
A combinator explains the relationship between selectors.
| Combinator | Example | Selects |
|---|---|---|
| descendant (space) | div p | All <p> inside <div> |
| child (>) | div > p | <p> that are direct children of <div> |
| next sibling (+) | div + p | The first <p> right after a <div> |
| subsequent sibling (~) | div ~ p | All <p> after a <div> (same parent) |
Example
<style>
.box > p { color: #04AA6D; font-weight: bold; }
.box + p { background: yellow; }
</style>
<div class="box">
<p>Direct child (green)</p>
<section><p>Grandchild (not green)</p></section>
</div>
<p>First paragraph after .box (yellow)</p>
<p>Second paragraph (normal)</p>
Keep reading “CSS Combinators”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.