Styling siblings with CSS has never been easier. Experimenting with sibling-count and sibling-index

September 19, 2025

A fan of red and orange striped playing cards on a green background, surrounded by four UI elements: stacked translucent squares (top left), numbered purple circles in a grid (top right), a gradient bar chart labeled "Perfect!" (bottom left), and a horizontal color palette from teal to purple (bottom right).

If I were to divide CSS evolutions into categories, then last year was probably the year that ended with animations and colors getting better; This year, the end of the year seems to be about those ease-of-life features. We had one of those not that long go with :has(), but with things such as sibling-count, sibling-index, functions, and conditionals, the way we write CSS might just change for the better once again. In this article, I want to dip my toe in sibling-index() and sibling-count(), while also carefully adding some functions in the mix.

Source: Styling siblings with CSS has never been easier. Experimenting with sibling-count and sibling-index | utilitybend

Years ago, CSS introduced the adjacent sibling selector, but it was limited in that it could only select an element that follows another element as its sibling.
Sibling selection has got more sophisticated in recent times, and here we can learn all about sibling selection in CSS today.