CSS: subsequent sibling selector (~)

By Xah Lee. Date: . Last updated: .

Subsequent-Sibling Combinator

s1 ~ s2

Match all s2 that has a older brother s1.

Each expression can be compound selector.

/* make list items red, except first */
li ~ li {
 color: red;
}
<ul>
 <li>cat</li>
 <li>dog (match)</li>
 <li>bird (match)</li>
</ul>

Example. All paragraphs after a heading

/* all p elements that are siblings of h2 and come after it */
h2 ~ p {
 font-weight: bold;
}

CSS selectors by sibling criteria

CSS. Selectors

Selector types
Simple selectors
Combinators
Selector list
Special selector
Misc