The CSS adjacent sibling combinator (+
) is used to select the adjacent or next sibling element of a given element.
A combinator combines selectors in a way that gives them a useful relationship to each other.
first_element + target_element { style properties }
The adjacent sibling combinator (+
) only matches the second element (target_element
) if it immediately follows the first element (first_element
) and if both selectors are children of the same parent element.
In this example, we add a background-color
property to the adjacent sibling (p
) element of the div
element.
Both p
and div
elements have the same parent, body
element.
Notice that the property is not applied to the second
p
element because it is not the immediate next sibling to thediv
element.
Free Resources