MDN self-hosted library · e01.org

Next-sibling combinator

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

css
/* Paragraphs that come immediately after any image */
img + p {
  font-weight: bold;
}
html
<ul>
  <li>One</li>
  <li>Two!</li>
  <li>Three</li>
</ul>
css
li:first-of-type + li {
  color: red;
  font-weight: bold;
}
html
<ul>
  <li>One</li>
  <li>Two</li>
  <li>Three!</li>
  <li>Four</li>
</ul>
css
li:has(+ li:last-of-type) {
  color: red;
  font-weight: bold;
}