General sibling combinator

The general sibling combinator (~) separates two selectors and matches all iterations of the second element, that are following the first element (though not necessarily immediately), and are children of the same parent element.

/* Paragraphs that are siblings of and
   subsequent to any image */
img ~ p {
  color: red;


former_element ~ target_element { style properties }



p ~ span {
  color: red;


<span>This is not red.</span>
<p>Here is a paragraph.</p>
<code>Here is some code.</code>
<span>And here is a red span!</span>
<span>And this is a red span!</span>
<code>More code...</code>
<div> How are you? </div>
<p> Whatever it may be, keep smiling. </p>
<h1> Dream big </h1>
<h2> that's all. </h2> 
<span>And yet again this is a red span!</span>



Specification Status Comment
Selectors Level 4
The definition of 'subsequent-sibling combinator' in that specification.
Working Draft Renames it the "subsequent-sibling" combinator.
Selectors Level 3
The definition of 'general sibling combinator' in that specification.
Recommendation Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Chrome Edge Firefox Internet Explorer Opera Safari
General sibling combinator (A ~ B) 1 12 1 7 9 3
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
General sibling combinator (A ~ B) ≤37 18 4 14 1 1.0

See also

© 2005–2020 Mozilla and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.