CSS Adjacent Sibling Selector (+)

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

What You’ll Learn

The element + element selector — also called the adjacent sibling combinator — targets an element only when it is the very next sibling after another element. It is perfect for precise spacing and typography tweaks.

01

+ combinator

Next sibling only.

02

Syntax

el1 + el2

03

Headings

Style intro paragraphs.

04

Forms

Label-to-input spacing.

05

vs ~

One vs all siblings.

06

Clean CSS

Avoid extra classes.

Introduction

The element + element selector in CSS is used to select an element that is directly preceded by another specified element. Both elements must share the same parent and sit next to each other in the HTML.

This combinator is useful when you want to style one specific neighbor — for example, the first paragraph after a heading — without affecting other similar elements further down the page.

Definition and Usage

Write the first selector, a plus sign (+), then the second selector. The rule applies only when the second element is the immediate next sibling of the first. If any other element sits between them, the selector does not match.

💡
Beginner Tip

Think of + as “the very next brother or sister element.” If you need all following siblings, use the general sibling combinator ~ instead.

📝 Syntax

The signature of the adjacent sibling selector is:

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

Basic Example

adjacent-sibling.css
h2 + p {
  color: #2563eb;
  font-weight: 600;
  margin-top: 0;
}

Syntax Rules

  • Both elements must be siblings under the same parent.
  • Only the first matching next sibling is selected.
  • No other elements may appear between the two siblings.
  • Spaces around + are conventional: h2 + p.
  • Works with types, classes, IDs, and attribute selectors.

Related Selectors

  • element ~ element — general sibling (all following siblings)
  • element element — descendant combinator (nested inside)
  • element > element — direct child combinator

⚡ Quick Reference

QuestionAnswer
Combinator symbol+ (plus)
Also calledAdjacent sibling combinator
MatchesOnly the immediate next sibling
Common patternh2 + p, label + input
Alternative for many siblingselement ~ element
Browser supportAll modern browsers
h2 + p label + input .card + .card #title + .subtitle

When to Use element + element

The adjacent sibling selector shines when the relationship is “right after”:

  • Intro paragraphs — Style the first paragraph after a heading differently from body text.
  • Form fields — Add margin between a label and its input when they are siblings.
  • Stacked components — Use .item + .item for gap between consecutive cards or list rows.
  • Toolbar buttons — Add left margin to a button that follows another button.
  • Figure captions — Target a caption element immediately after an image.

👀 Live Preview

Only the first paragraph after the heading is styled by h3 + p:

Section Title

This paragraph is adjacent to the heading.

This paragraph is not adjacent to the heading.

Examples Gallery

Practice the + combinator with headings, forms, cards, and sibling comparisons.

📜 Core Patterns

Target the single element that immediately follows another sibling.

Example 1 — Heading and adjacent paragraph

Style only the paragraph that directly follows an <h2>.

heading-paragraph.html
<style>
  h2 + p {
    color: #2563eb;
    font-weight: 600;
    margin-top: 0;
  }
</style>

<h2>Section Title</h2>
<p>This paragraph is adjacent to the heading.</p>
<p>This paragraph is not adjacent to the heading.</p>
Try It Yourself

How It Works

The first <p> is the immediate next sibling of <h2>. The second paragraph has a different preceding sibling (the first paragraph), so it is not matched.

Example 2 — Label and input spacing

Add top margin to an input that directly follows its label.

label-input.css
label + input {
  display: block;
  margin-top: 0.35rem;
  margin-bottom: 1rem;
}
Try It Yourself

How It Works

When label and input are siblings in the markup, label + input spaces them without wrapping each pair in an extra div class.

📄 Layout Patterns

Use + for stacked lists and compare with the general sibling combinator.

Example 3 — Spacing between consecutive cards

Add top margin only when one card follows another.

card-stack.css
.card + .card {
  margin-top: 0.75rem;
}
Try It Yourself

How It Works

The first card has no top margin from this rule. Each card that immediately follows another card gets spacing — a clean alternative to margin-bottom on every item.

Example 4 — Adjacent (+) vs general (~) sibling

See why + matches one sibling while ~ would match all following siblings.

plus-vs-tilde.css
/* Only the first p after h2 */
h2 + p { color: #2563eb; }

/* All p siblings after h2 */
h2 ~ p { color: #16a34a; }
Try It Yourself

How It Works

h2 + p stops at the first paragraph. If you need every paragraph after the heading, switch to h2 ~ p.

⚠️ Common Pitfalls

  • Elements in between — A comment, wrapper, or extra tag between siblings breaks the match. The second element must be directly next in the DOM.
  • Only one sibling+ never selects multiple elements. Use ~ for that.
  • Wrong parent — Siblings must share the same parent. Cousins or nested elements do not qualify.
  • Markup structure — If your label wraps the input, label + input will not work; adjust HTML or use a different selector.

♿ Accessibility

  • Keep semantic HTML — Combinators style structure; they do not replace proper heading levels or label associations.
  • Do not hide content with + alone — If only the adjacent element is styled differently, ensure meaning is still clear to screen reader users.
  • Focus order — When styling label + input, keep logical tab order and visible focus styles on inputs.
  • Color contrast — Highlighted intro text must still meet contrast guidelines.

🧠 How element + element Works

1

Browser reads the DOM tree

Elements are grouped by parent. Siblings are children listed one after another.

Structure
2

First selector finds anchors

Every matching element1 becomes a starting point.

Match
3

+ checks the next sibling

If the very next sibling matches element2, styles apply.

Combinator
=

Precise styling

Only the intended neighbor element is affected.

Browser Compatibility

The adjacent sibling combinator is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera.

Universal · All browsers

Reliable combinator support

The + selector has been supported across browsers for many years and works consistently on desktop and mobile.

99% Browser 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 versions
Full support
+ adjacent sibling combinator 99% supported

Bottom line: Safe to use element + element in any modern project.

Conclusion

The element + element adjacent sibling selector is a powerful way to style elements based on their immediate neighbor in the DOM. It keeps CSS focused and avoids sprinkling extra classes on every second element.

Use + when you need exactly one next sibling. Reach for ~ when you need every following sibling. Together, these combinators help you write cleaner, more maintainable stylesheets.

💡 Best Practices

✅ Do

  • Use + for intro paragraphs after headings
  • Try .item + .item for stack spacing
  • Combine with classes for specific components
  • Switch to ~ when you need all siblings
  • Keep HTML siblings flat when you rely on +

❌ Don’t

  • Expect + to skip over elements in between
  • Use + when markup wraps inputs inside labels
  • Overcomplicate with + chains unless necessary
  • Forget that only the next sibling matches
  • Rely on + for deeply nested relationships

Key Takeaways

Knowledge Unlocked

Five things to remember about +

Use these points when targeting sibling elements.

5
Core concepts
📄 02

Same parent

Must be siblings.

Rule
📝 03

h2 + p

Classic pattern.

Example
~ 04

vs ~

One vs all siblings.

Compare
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The adjacent sibling selector (element1 + element2) selects element2 only when it immediately follows element1 as the next sibling in the HTML.
The + combinator matches only the single next sibling. The ~ general sibling combinator matches all following siblings at the same level.
Spaces around the + sign are required for readability and valid parsing. The two elements must still be direct siblings with no other elements between them in the DOM.
Yes. Selectors like .intro + p or #title + span work the same way — the second element must be the immediate next sibling of the first.
Yes. All modern browsers support the + combinator. It has been part of CSS for many years.

Practice in the Live Editor

Open the HTML editor and experiment with h2 + p, label + input, and other adjacent sibling patterns.

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