General Sibling (~) combinator
Specifies an adjacent sibling relationship between selector elements.
![]() |
Syntax
first~second { ... }
Parameters
- first
-
A CSS simple selector.
- second
-
A CSS simple selector.
Standards information
- Selectors Level 3, Section 6.3
Remarks
The general sibling combinator is a "tilde" (~) character that separates two simple selectors. Whitespace is not significant.
A selector of the form "E~F" matches element F when it follows sibling element E in the document tree, ignoring non-element nodes (such as text nodes and comments). Element E and F must share the same parent but does not necessarily precede F directly. To match the first child of the parent, use the :first-child pseudo-class.
Examples
The following example applies the style rule to the first letter of each paragraph that follows an h1 but does not applies to other paragraphs preceding the h1.
<!DOCTYPE html>
<html>
<head>
<style>
h1 ~ p:first-letter {
text-decoration:underline; color: red;
}
</style>
</head>
<body>
<p>This paragraph is not affected by the style rule.</p>
<h1>Header One</h1>
<h2>Header Two</h2>
<p>Paragraph text with style rule applied.</p>
<div>
Other text with no style applied</div>
<p>Paragraph text with style rule applied.</p>
</body>
</html>
