Home CSS Selectors + CSS Adjacent Sibling Combinator (+) Definition
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(+ …) .
Syntax
CSS Syntax Whitespace around + is optional but recommended. Example: h2 + p.
Patterns
Selector Patterns Pattern Description Try it h2 + pParagraph that immediately follows an h2 Try itli:first-of-type + liSecond list item when it follows the first Try it.label + inputInput right after a label sibling Try ith2 ~ p (compare)All following p siblings—not just the next one Try it
Approach
How to Use + Write the “before” selector, then +, then the element you want to style.
Confirm both elements share the same parent in the HTML. Confirm nothing sits between them (no wrapper, no extra tag). Write former + target { … }. If you need every following sibling, switch to ~. Piece Required? Role Former selector Yes The sibling that comes first +Yes Requires an immediate next sibling Target selector Yes The element that receives the styles Same parent Yes Both must be siblings in the DOM
Try it
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.
Code
CSS Examples Each snippet focuses on the + combinator. Use Try It Yourself for a live editor.
1. Heading + p 2. List items 3. + vs ~ Example 1 — Paragraph After a Heading Style only the first paragraph under a heading.
h2 + p {
color: #1d4ed8;
font-weight: bold;
} Title This paragraph is adjacent
This one is not
Only the first p matches h2 + p.
How It Works Pick the former element. h2 is the sibling that comes first.Add +. Require an immediate next sibling.Style the target. p gets bold blue text.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).
li:first-of-type + li {
color: red;
font-weight: bold;
} Only “Two!” matches li:first-of-type + li.
How It Works Find the first li. :first-of-type marks item One.Require the next sibling. + points at the following li.Style that next item. Item Two turns red and bold.Leave the rest. Item Three is not adjacent to the first item.Example 3 — + vs ~ See how many following paragraphs each combinator styles.
.demo-plus h2 + p {
background: #dbeafe;
}
.demo-tilde h2 ~ p {
background: #bbf7d0;
} h2 + p
Plus Adjacent only
Skipped
h2 ~ p
Tilde Following
Also following
+ paints one paragraph; ~ paints every following p.
How It Works Same HTML shape. Both demos use a heading then two paragraphs.Use +. Only the first p after the heading matches.Use ~. Every following p sibling matches.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.
Compatibility
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.
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.
Remember
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 What does the CSS adjacent sibling combinator do? The + combinator matches the second selector only when that element immediately follows the first element, and both share the same parent.
What is the difference between + and ~? + matches only the next sibling. ~ matches every following sibling that fits the second selector.
Does whitespace around + matter? Whitespace around + is optional but recommended for readability. The elements must still be immediate siblings in the DOM.
Can + select a previous sibling? Not by itself—it only looks forward. To style a previous sibling, use :has(+ …), for example li:has(+ li:last-of-type).
Do the two elements need the same tag name? No. Any selectors work, such as h2 + p or .intro + ul, as long as the second element is the immediate next sibling.
Is the + combinator a runtime API? No. It is a browser CSS combinator, not a Node.js feature.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion