Next-sibling combinator

The next-sibling combinator (+) separates two selectors and matches the second element only if it immediately follows the first element, and both are children of the same parent element.

css

/* Paragraphs that come immediately after any image */
img + p {
  font-weight: bold;
}

Syntax

css

/* The white space around the + combinator is optional but recommended. */
former_element + target_element { style properties }

Examples

CSS

css

li:first-of-type + li {
  color: red;
}

HTML

html

<ul>
  <li>One</li>
  <li>Two!</li>
  <li>Three</li>
</ul>

Result

Specifications

No specification found

No specification data found for css.selectors.next-sibling.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

BCD tables only load in the browser

See also