+
is the adjacent sibling combinator.
That means the selector h2 + p
only selects the p
that comes immediately after an h2
.
An illustration:
<h2>Headline!</h2>
<p>The first paragraph.</p> <!-- Selected [1] -->
<p>The second paragraph.</p> <!-- Not selected [2] -->
<h2>Another headline!</h2>
<blockquote>
<p>A quotation.</p> <!-- Not selected [3] -->
</blockquote>
What’s selected and what’s not:
-
Selected
Thisp
comes right after the firsth2
. -
Not selected
Thisp
occurs after the firstp
as opposed to theh2
. Since it doesn’t immediately follow theh2
, it’s not selected.However, since it still follows the
h2
element, just not immediately, the selectorh2 + p
won’t match this element, buth2 ~ p
will, using the general sibling combinator instead. -
Not selected
Thisp
is located within ablockquote
, and there’s noh2
before it inside the quote to satisfy its selector.