CSS Subsequent-Sibling Combinator (~) Selector
Description
The Subsequent-Sibling Combinator ( selector, is used in CSS to target elements that share the same parent and appear after a specified element in the document tree. Unlike the )Child Combinator (>), which only selects immediate children, the Subsequent-Sibling Combinator () selector does not require the matched elements to be directly adjacent; any element that follows the specified element, as long as they share the same parent, will be selected. This makes it especially useful for styling groups of elements dynamically based on the presence of a preceding element.
One practical use of the Subsequent-Sibling Combinator (~) selector is in creating interactive or state-based designs. For instance, when combined with form elements such as checkboxes or radio buttons, it can be used to style subsequent content when a particular input is checked. Consider the following example:
<div>
<input type="checkbox" id="toggle">
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<p>Paragraph 3</p>
</div>
#toggle:checked ~ p {
color: green;
font-weight: bold;
}
In this example, whenever the checkbox with id toggle is checked, all subsequent p elements that share the same parent are styled with a green, bold font. This demonstrates the selector's ability to propagate styles to multiple siblings after a triggering element.
The Subsequent-Sibling Combinator (~) selector is also useful in layouts or lists where you want to apply styling to items following a specific type of element without changing the HTML structure. For example, in a menu or a list, if one item needs to be highlighted differently, all items that follow can inherit or respond to this condition, often combined with pseudo-classes like :hover or :checked.
By providing a mechanism to select non-adjacent elements efficiently, the Subsequent-Sibling Combinator (~) selector enables more flexible and maintainable CSS, reducing the need for extra classes or JavaScript-based styling. Its behavior emphasizes document order and hierarchy, allowing designers to create cascading effects and interactions purely with CSS.
Syntax
element1 ~ element2 { css declarations; }
Example
Browser Support
The following information will show you the current browser support for the CSS Subsequent-Sibling Combinator (~) selector. Hover over a browser icon to see the version that first introduced support for this selector.
This CSS subsequent-sibling combinator (~) selector is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 3rd January 2026
