CSS Combinators
What are Combinators?
Combinators define relationships between selectors. They let you target elements based on their position relative to other elements in the DOM tree.
Descendant Selector (Space)
The space combinator selects all descendants (children, grandchildren, etc.) of an element.
Child Selector (>)
The > combinator selects only direct children, not deeper
descendants.
Adjacent Sibling Selector (+)
The + combinator selects the element immediately
following another element (same parent).
General Sibling Selector (~)
The ~ combinator selects all siblings following an
element (not just the immediate one).
Combining Multiple Combinators
Chain combinators together for precise targeting. Read from right to left!
Practical Example: Form Layout
Use combinators to style form elements based on their relationships.
> instead of descendant selector
(space) when possible for better performance and
more predictable styling!
Summary
A B(space) - Descendant: all B inside AA > B- Child: direct children B of AA + B- Adjacent sibling: B immediately after AA ~ B- General sibling: all B siblings after A- Combinators can be chained for precise targeting
- Read complex selectors from right to left
Quick Quiz
Which combinator selects only direct children?
Enjoying these tutorials?