The CSS child combinator (>
) can be used to select all elements that are the immediate children of a specified element.
A combinator combines and explains the relationship between two or more selectors.
selector1 > selector2 { style properties }
It matches only those elements matched by the second selector (selector2
) that are the direct children of elements matched by the first selector (selector1
).
In this example, add a background-color
property to all the immediate child (p
) elements of the parent (div
) element.
Notice that the CSS property does not apply to the third
p
element as it is not an immediate child.
Free Resources