CSS General Sibling Selector (~)

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Combinators

What You’ll Learn

The general sibling combinator element1 ~ element2 selects every sibling that follows the first element. Use it when you need to style all later siblings, not just the immediate next one.

01

~ tilde

Combinator.

02

Siblings

Same parent.

03

All after

Not just next.

04

+ vs ~

One vs many.

05

h2 ~ p

Common pattern.

06

Layout

Dynamic CSS.

Introduction

The general sibling combinator element1 ~ element2 in CSS selects an element that is a sibling of another specified element. Both elements must share the same parent and the matched element must appear after the first one in the document.

This selector is particularly useful for applying styles to multiple elements that follow a heading, label, or section marker — without adding extra classes to every sibling.

Definition and Usage

Write the first selector, a tilde (~), then the second selector. Every matching element2 that comes after element1 at the same nesting level receives the styles. Other elements may appear between them; unlike +, they do not break the match.

💡
Beginner Tip

If you only need the very next sibling, use + instead. Use ~ when you want all following siblings — for example every paragraph after a section heading.

📝 Syntax

The signature of the general sibling selector is:

syntax.css
element1 ~ element2 {
  /* CSS properties */
}

This syntax targets element2 when it is preceded by element1 and both elements share the same parent.

Basic Example

general-sibling.css
h2 {
  color: #2563eb;
}

h2 ~ p {
  color: #15803d;
  font-style: italic;
}

+ vs ~ Comparison

element1 + element2 Matches only the immediate next sibling. Stops after one match.
element1 ~ element2 Matches all following siblings of the same type/selector.

Syntax Rules

  • Both elements must be siblings under the same parent.
  • Only siblings that come after element1 are matched.
  • Other elements may appear between the two siblings (unlike +).
  • Spaces around ~ are conventional: h2 ~ p.
  • Works with types, classes, IDs, and attribute selectors.

Related Selectors

h2 ~ p .title ~ p input ~ label .item ~ .item

⚡ Quick Reference

QuestionAnswer
Combinator symbol~ (tilde)
Also calledGeneral sibling combinator
MatchesAll following siblings at the same level
Common patternh2 ~ p, .section ~ .note
When to use + insteadOnly the immediate next sibling
Browser supportAll modern browsers

When to Use element ~ element

The general sibling combinator is ideal when multiple elements follow a marker:

  • Section body text — Style all paragraphs after a heading in an article block.
  • Form groups — Apply spacing or color to every label after a checkbox input.
  • FAQ lists — Style all answer paragraphs that follow a question heading.
  • Repeating rows — Use .row ~ .row for borders between stacked items.
  • Toggle panels — Style content blocks that follow a control element as siblings.

👀 Live Preview

h2 ~ p styles all paragraphs after the heading, not just the first one:

Heading 1

This is the first paragraph.

This is the second paragraph.

Heading 2

This is another paragraph.

Examples Gallery

Practice the ~ combinator with headings, sections, forms, and + vs ~ comparisons.

📜 Core Patterns

Style every sibling that follows a specified element.

Example 1 — Heading and all following paragraphs

Style every <p> that follows an <h2> within the same container.

h2-paragraph.css
h2 {
  color: #2563eb;
}

h2 ~ p {
  color: #15803d;
  font-style: italic;
}
Try It Yourself

How It Works

Every <p> that follows an <h2> under the same parent matches h2 ~ p. When a new heading appears, the pattern resets for paragraphs after that heading.

Example 2 — Section title and body paragraphs

Use a class on the section title and style all following paragraphs in that block.

section-sibling.css
.section-title ~ p {
  color: #475569;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.section-title ~ p:last-of-type {
  margin-bottom: 0;
}
Try It Yourself

How It Works

.section-title ~ p applies body-text styles to every paragraph after the title. Pairing with :last-of-type removes extra bottom margin on the final paragraph.

📄 Forms & Comparison

Form sibling patterns and + vs ~ differences.

Example 3 — Checkbox and following labels

Style sibling labels that follow a checkbox input in a custom form layout.

checkbox-label.css
input[type="checkbox"] ~ label {
  display: block;
  margin-left: 1.5rem;
  color: #334155;
  font-size: 0.875rem;
}

input[type="checkbox"]:checked ~ label {
  color: #15803d;
  font-weight: 600;
}
Try It Yourself

How It Works

When the checkbox and labels are siblings, input ~ label indents all labels that follow the input. Combined with :checked, you can highlight options when the box is selected.

Example 4 — + vs ~ side by side

See how h2 + p matches one paragraph while h2 ~ p matches all of them.

plus-vs-tilde.css
/* Adjacent: only the first paragraph */
h2 + p {
  color: #2563eb;
  font-weight: 600;
}

/* General: all paragraphs after h2 */
h2 ~ p {
  color: #15803d;
  font-style: italic;
}
Try It Yourself

How It Works

With +, only the first paragraph after the heading is blue and bold. With ~, every following paragraph turns green and italic. Choose based on how many siblings you need to style.

💬 Usage Tips

  • Style many siblings at once — Use ~ instead of repeating classes on every element.
  • Combine with pseudo-classes — Patterns like input:checked ~ .panel enable toggle UIs without JavaScript.
  • Scope with a parent class — Write .article h2 ~ p to limit matches to one section.
  • Prefer + for spacing — Use .item + .item for gap between consecutive items; use ~ when all following items need the same style.
  • Read HTML top to bottom — Remember that only siblings after the first selector are matched.

⚠️ Common Pitfalls

  • Only following siblings — Elements before element1 are never matched by ~.
  • Must share a parent — Nested descendants are not siblings; the combinator will not match them.
  • Confusing + and ~+ stops at the next sibling; ~ continues through all later siblings.
  • New headings reset context — Paragraphs after a second <h2> match relative to that heading, not the first one.
  • Over-broad rules — A bare h2 ~ p on a complex page may style more paragraphs than intended; scope when needed.

♿ Accessibility

  • Do not hide content with CSS alone — Avoid using sibling selectors to remove important text from view.
  • Form associations — Prefer <label for="id"> over relying solely on sibling layout for accessibility.
  • Color contrast — Styled sibling text must still meet WCAG contrast ratios.
  • Focus order — Sibling-based form layouts should preserve logical tab order in HTML.
  • Semantic structure — Use proper heading levels so screen readers benefit from your section patterns.

🧠 How ~ Works

1

Find element1

The browser locates all elements matching the first part of the selector, such as h2.

Match
2

Scan later siblings

For each match, the engine checks following siblings under the same parent.

Siblings
3

Apply to all matches

Every sibling matching element2 gets the CSS properties — not just the first one.

Style
=

Flexible layouts

Multiple siblings share styles based on what precedes them in the HTML.

🖥 Browser Compatibility

The general sibling combinator is supported in all modern browsers and has been available for many years.

Baseline · Universal support

Sibling combinators everywhere

element ~ element works reliably in Chrome, Firefox, Safari, Edge, and Opera.

99% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
~ general sibling combinator 99% supported

Bottom line: element ~ element is safe for production layouts in all modern projects.

🎉 Conclusion

The element1 ~ element2 selector is a versatile tool for targeting sibling elements in your CSS. By understanding how the general sibling combinator works, you can create more flexible and dynamic styles for headings, sections, forms, and stacked components.

Pair it with the adjacent sibling combinator (+) in your mental toolkit: use + for the immediate neighbor and ~ when every following sibling should share the same look.

💡 Best Practices

✅ Do

  • Use ~ when multiple siblings need the same style
  • Scope with a parent class when needed
  • Combine with :checked for toggle patterns
  • Compare + vs ~ before choosing
  • Keep HTML sibling order logical

❌ Don’t

  • Expect ~ to match earlier siblings
  • Use ~ between nested descendants
  • Confuse ~ with the descendant space
  • Write overly broad h2 ~ p on large pages
  • Forget that a new heading resets context

Key Takeaways

Knowledge Unlocked

Five things to remember about ~

Use these points when styling sibling elements.

5
Core concepts
All 02

Following

Every sibling.

Scope
+ 03

vs +

One vs many.

Compare
h2 04

h2 ~ p

Classic use.

Pattern
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The general sibling combinator (element1 ~ element2) selects all element2 nodes that follow element1 and share the same parent. Unlike +, it matches every following sibling, not just the immediate next one.
The + adjacent sibling combinator matches only the single next sibling. The ~ general sibling combinator matches all later siblings at the same level, even if other elements appear between them.
Yes. The ~ combinator only works between siblings — elements that share the same parent in the DOM. Nested descendants are not matched.
No. The general sibling combinator only matches siblings that come after element1 in document order. Earlier siblings are ignored.
Yes. All modern browsers support the ~ combinator. It has been part of CSS for many years and is safe for production use.

Practice in the Live Editor

Open the HTML editor and experiment with h2 ~ p, form sibling patterns, and + vs ~ comparisons.

HTML Editor →

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.

5 people found this page helpful