CHAPTER 28
CSS Combinators
Learn how CSS combinators select elements based on their relationship with other elements.
01. What is CSS Combinators?
Combinators describe relationships between selectors.
The descendant combinator selects elements inside another element.
Child, adjacent sibling and general sibling combinators provide more precise control.
02. Syntax
/* Descendant */
div p { }
/* Child */
div > p { }
/* Adjacent sibling */
h1 + p { }
/* General sibling */
h1 ~ p { }
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.card p {
color: #2563eb;
}
.card > h2 {
color: #ec4899;
}
h2 + p {
font-weight: bold;
}
</style>
</head>
<body>
<div class="card">
<h2>AIFA CSS</h2>
<p>
Learn CSS combinators.
</p>
</div>
</body>
</html>
04. Important Points
✓
Space selects descendants.
✓
> selects direct children.
✓
+ selects the immediately following sibling.
✓
~ selects following siblings.
05. Common Mistakes
⚠
Using overly complicated selectors.
⚠
Confusing descendant and child selectors.
⚠
Writing selectors that are too specific.
06. Real World Use
Combinators are useful for navigation menus, cards, content sections and component-based CSS.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Practice Combinators
Create nested elements and demonstrate descendant, child and adjacent sibling selectors.