Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Selectors

The subsequent-sibling combinator (A ~ B)

Reference for the CSS subsequent-sibling combinator (~): select all later siblings of an element, and how it differs from the next-sibling combinator.

The subsequent-sibling (general sibling) combinator is written ~. A ~ B matches every B that comes after an A under the same parent, whether directly after it or several elements later. It only looks forward in the source order.

Compared with A + B, which needs B to follow A immediately, ~ is relaxed about what sits in between.

CSS
h2 ~ p {
  color: #495057;
}

Try it

All later siblings

Syntax and arguments

CSS
A ~ B { }                      /* any later sibling B of A */
#toggle:checked ~ .panel { }   /* a classic "checkbox hack" */
.step.done ~ .step { }         /* steps after the completed one */
Part Description
A Selector for an earlier sibling (not styled).
~ The subsequent-sibling combinator.
B Selector for the later siblings that receive the styles.

Specificity is the sum of both sides. The elements must share a parent.

Usage notes

  • Same parent only. Siblings must be children of the same element. It cannot reach into a parent's neighbours.
  • Forward only. A selector cannot look at earlier siblings. For "has a following sibling" conditions use :has(), for example li:has(~ li.current).
  • State toggles. input:checked ~ .panel shows or hides a panel based on a checkbox or radio placed earlier in the markup. It works without JavaScript, but check keyboard focus and screen-reader behavior, and prefer <details> or buttons with ARIA where they fit.
  • Source order. Visual position can be changed with Flexbox, Grid or order, but the combinator follows the DOM order.
  • Progress indicators. .done ~ .step styles "not finished yet" steps in a stepper without extra classes.
  • Broader than you think. On long lists, ~ can match many elements; prefer + when you really mean "the next one".

Browser support

Supported in every browser.