CSS Adjacent Sibling Combinator (+)

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

Definition and Usage

The next-sibling combinator (+) matches the second element only if it immediately follows the first element, and both share the same parent.

MDN also calls it the adjacent sibling combinator. Use it for patterns like “the paragraph right after a heading” or “the next list item.”

Note Only the next sibling

+ styles one following element. If anything sits between the two tags in the HTML, the match fails. For all following siblings, use ~.

Note Previous sibling needs :has()

+ only looks forward. To style the element before another, use :has(+ …).

CSS Syntax

syntax.css
former + target { … }

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

Selector Patterns

PatternDescriptionTry it
h2 + pParagraph that immediately follows an h2Try it
li:first-of-type + liSecond list item when it follows the firstTry it
.label + inputInput right after a label siblingTry it
h2 ~ p (compare)All following p siblings—not just the next oneTry it

How to Use +

Write the “before” selector, then +, then the element you want to style.

  1. Confirm both elements share the same parent in the HTML.
  2. Confirm nothing sits between them (no wrapper, no extra tag).
  3. Write former + target { … }.
  4. If you need every following sibling, switch to ~.
PieceRequired?Role
Former selectorYesThe sibling that comes first
+YesRequires an immediate next sibling
Target selectorYesThe element that receives the styles
Same parentYesBoth must be siblings in the DOM

Live Preview

Only the paragraph that sits right after the heading is bold and blue—via h2 + p. The later paragraph is a sibling too, but not adjacent, so it stays normal.

h2 + p demo

Compare the first p (matched) with the second p (skipped).

Adjacent sibling preview

Heading

Right after the heading (matched by h2 + p)

Later sibling (not adjacent)

Rule used: .tut-adj-stage h2 + p

CSS Examples

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

Example 1 — Paragraph After a Heading

Style only the first paragraph under a heading.

CSS
h2 + p {
  color: #1d4ed8;
  font-weight: bold;
}
Try It Yourself

How It Works

  1. Pick the former element. h2 is the sibling that comes first.
  2. Add +. Require an immediate next sibling.
  3. Style the target. p gets bold blue text.
  4. Skip later siblings. A second p is not adjacent, so it stays unchanged.

Example 2 — Next List Item

Highlight the item that follows the first list item (MDN pattern).

CSS
li:first-of-type + li {
  color: red;
  font-weight: bold;
}
Try It Yourself

How It Works

  1. Find the first li. :first-of-type marks item One.
  2. Require the next sibling. + points at the following li.
  3. Style that next item. Item Two turns red and bold.
  4. Leave the rest. Item Three is not adjacent to the first item.

Example 3 — + vs ~

See how many following paragraphs each combinator styles.

CSS
.demo-plus h2 + p {
  background: #dbeafe;
}

.demo-tilde h2 ~ p {
  background: #bbf7d0;
}
Try It Yourself

How It Works

  1. Same HTML shape. Both demos use a heading then two paragraphs.
  2. Use +. Only the first p after the heading matches.
  3. Use ~. Every following p sibling matches.
  4. Choose by need. One next sibling → +; all later siblings → ~.

Edge Cases & Pitfalls

Most misses come from HTML structure, not from the + itself.

between

Anything in between breaks the match

A comment, text node that becomes an element, or another tag between the two siblings means + will not match.

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 ~

~ keeps matching later siblings. Reach for it when one next sibling is not enough.

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

Adjacent 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: only the immediate next sibling matches; use ~ or :has(+ …) for other cases.

Key Takeaways

  • Role: select the element that immediately follows another sibling.
  • Form: former + target under the same parent.
  • vs ~: one next sibling vs all following siblings.
  • Tip: look backward with :has(+ …), not with bare +.

One line: A + B styles B only when it is the next sibling of A.

Frequently Asked Questions

The + combinator matches the second selector only when that element immediately follows the first element, and both share the same parent.
+ matches only the next sibling. ~ matches every following sibling that fits the second selector.
Whitespace around + is optional but recommended for readability. The elements must still be immediate siblings in the DOM.
Not by itself—it only looks forward. To style a previous sibling, use :has(+ …), for example li:has(+ li:last-of-type).
No. Any selectors work, such as h2 + p or .intro + ul, as long as the second element is the immediate next sibling.
No. It is a browser CSS combinator, not a Node.js feature.

Next: General sibling (~)

Learn how to style every following sibling with the ~ combinator.

~ 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