CSS General Sibling Combinator (~)

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The subsequent-sibling combinator (~) matches every element that follows another sibling, shares the same parent, and matches the second selector. Elements may sit between them.

MDN also calls it the general sibling combinator. Use it for patterns like “all paragraphs after a heading” or “every span after a paragraph.”

Baseline Widely available.

Long-supported CSS combinator. Safe for production layouts across modern browsers.

Note — forward only.

~ never styles earlier siblings. To look backward, use :has(~ …). For only the next sibling, use +.

CSS Syntax

syntax.css
former ~ target { … }

Whitespace around ~ is optional but recommended. Example: h2 ~ p.

Selector Patterns

PatternDescriptionTry it
h2 ~ pEvery p that follows an h2 siblingTry it
p ~ spanEvery span after a p (gaps allowed)Try it
.note ~ pParagraphs that follow a .note siblingTry it
h2 + p (compare)Only the immediate next pTry it
same parentTargets must share a parent with the formerTry it
gaps allowedOther siblings between still match with ~Try it

How to Use ~

Write the “before” selector, then ~, then the siblings you want to style.

  1. Confirm both sides share the same parent in the HTML.
  2. Confirm the targets come after the former element.
  3. Write former ~ target { … }.
  4. If you need only the next sibling, switch to +.
PieceRequired?Role
Former selectorYesThe sibling that comes first
~YesSelects all following matching siblings
Target selectorYesElements that receive the styles
Same parentYesBoth must be siblings in the DOM

Live Preview

Switch between ~ and + on the same markup. Watch how many following paragraphs light up.

~ styles every following p. + styles only the first one.

Sibling preview

Heading

First paragraph after heading

A note between paragraphs

Later paragraph (still a following sibling)

Rule: h2 ~ p — both paragraphs match

CSS Examples

Each snippet focuses on the ~ combinator. Use Try It Yourself for a live editor.

Example 1 — All Paragraphs After a Heading

Style every following p, even when other siblings sit between.

CSS
h2 ~ p {
  color: #15803d;
  font-weight: bold;
}
Try It Yourself

How It Works

  1. Pick the former element. h2 comes first.
  2. Add ~. Look forward through following siblings.
  3. Style matching targets. Every later p turns green and bold.
  4. Ignore gaps. A note between paragraphs does not block ~.

Example 2 — p ~ span

MDN-style pattern: spans that follow a paragraph under the same parent.

CSS
p ~ span {
  color: #b91c1c;
}
Try It Yourself

How It Works

  1. Start from p. The paragraph is the former sibling.
  2. Match later spans. ~ finds every following span.
  3. Skip earlier spans. A span before the paragraph does not match.
  4. Allow other nodes. A code element between does not stop the match.

Example 3 — ~ vs +

Same HTML, different combinators.

CSS
.demo-tilde h2 ~ p {
  background: #bbf7d0;
}

.demo-plus h2 + p {
  background: #dbeafe;
}
Try It Yourself

How It Works

  1. Same structure. Heading, then two paragraphs.
  2. Use ~. Both paragraphs after the heading match.
  3. Use +. Only the immediate next paragraph matches.
  4. Choose by need. All later siblings → ~; one next sibling → +.

Edge Cases & Pitfalls

Most misses come from parent boundaries or looking the wrong direction.

parent

Must share a parent

Nested elements are not siblings. Use the child or descendant combinator for those.

direction

Forward only

p ~ h2 never styles a heading that comes before a paragraph. Use :has(~ …) to look backward.

vs +

Do not confuse with +

+ stops at the immediate next sibling. Reach for it when one match is enough.

gaps

Gaps are allowed

Unlike +, other siblings between the former and target do not break ~.

space

Spaces are optional

h2~p and h2 ~ p are both valid. Prefer spaces for reading.

Browser Support

The ~ combinator is a browser CSS selector. Node.js, Deno, and Bun do not evaluate it.

✓ Baseline · Widely available

General sibling (~)

Supported in all major browsers for decades (Baseline Widely available since about July 2015). Safe for production layouts.

99% All modern browsers
Google Chrome All
Full
Mozilla Firefox All
Full
Apple Safari All
Full
Microsoft Edge All
Full
Opera All
Full
Samsung Internet All
Full
Internet Explorer 7+
Full
former ~ target Universally supported

Bottom line: Production-ready. Remember: ~ matches all following siblings; use + for only the next one. Not a server runtime API.

Key Takeaways

  • Role: select all following siblings that match the second selector.
  • Form: former ~ target under the same parent.
  • vs +: all following siblings vs only the next one.
  • Tip: look backward with :has(~ …), not with bare ~.

One line: A ~ B styles every following sibling B after A.

Frequently Asked Questions

The ~ combinator (subsequent-sibling) matches every element that follows the first selector, shares the same parent, and matches the second selector. Elements in between are allowed.
+ matches only the immediate next sibling. ~ matches all following siblings that fit the second selector.
No. With ~, other siblings can sit between the former element and the targets. They must still share one parent.
Not by itself—it only looks forward. To style an earlier sibling, use :has(~ …) or :has(+ …).
Whitespace around ~ is optional but recommended for readability. Both h2~p and h2 ~ p are valid.
No. It is a browser CSS combinator, not a Node.js feature.

Next: Child combinator (>)

Learn how to select only direct children of a parent.

Child combinator tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful