CSS combinators define how selectors relate to each other. This enables more precise and targeted styling in complex HTML structures.
CSS has four fundamental combinators: descendant, child, adjacent sibling, and general sibling. These can be used in different ways to target HTML elements.
Combinator | Description |
---|---|
A B | Selects all B elements that are inside element A. |
A > B | Selects B elements that are direct children of A. |
A + B | Selects the first B element that comes immediately after A. |
A ~ B | Selects all B elements that follow A, not only immediately. |
The descendant combinator (space) selects all inner elements, while the child combinator (>) selects only direct children. This allows for more precise styling.
In the following example, you can see how the descendant and child combinators work:
The adjacent sibling combinator (+) selects only the immediately following sibling, while the general sibling combinator (~) selects all later siblings.
Combinators help with precise styling, but overusing them can make code complicated. Here are some tips:
Please sign in to ask Lara about CSS combinators.
Select Language
Set theme
© 2025 ReadyTools. All rights reserved.